我有一个哈希图数组,我将信息从 XML 文件中放入。我应该如何下载图像以使其在我的列表视图中可用?
这是我的代码:
public void dealsCb(String url, XmlDom xml, AjaxStatus status) {
List<XmlDom> products = xml.tags("Product");
List<HashMap<String, String>> titles = new ArrayList<HashMap<String, String>>();
for (XmlDom product : products) {
HashMap<String, String> hmdata = new HashMap<String, String>();
hmdata.put("title", product.text("Product_Name"));
hmdata.put("desc", product.text("Sale_Price"));
//NEED TO DOWNLOAD IMAGE FROM THIS URL AND THEN ADD TO ARRAY....
hmdata.put("thumb", product.text("Image_URL"));
titles.add(hmdata);
}
String[] from = { "thumb", "title", "desc" };
int[] to = { R.id.icon, R.id.title, R.id.desc };
SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), titles,
R.layout.activity_deals_item, from, to);
ListView listView = (ListView) findViewById(R.id.list);
listView.setAdapter(adapter);
}
我尝试了一种获取图像的方法,使其成为位图,然后将其转换为可绘制对象,但是由于 hmdata.put 需要一个字符串,因此无法将其添加到数组中...我在加载图像时缺少什么?