我正在尝试在列表视图中创建包含每种产品图像的产品列表。内容来自网络。
我已设法使用每个产品的名称创建列表视图,并在单击每个列表项时显示产品图像。但是我希望在生成列表时显示图像,我不知道如何执行此操作。
我真的很感激任何帮助。以下是我的活动代码:
NodeList nodes = doc.getElementsByTagName("result");
// Drawable d = null;
for (int i = 0; i < nodes.getLength(); i++) {
// HashMap<String, String> map = new HashMap<String, String>();
HashMap<String, Object> map = new HashMap<String, Object>();
Element e = (Element) nodes.item(i);
map.put("id", "ID: " + XMLfunctions.getValue(e, "id"));
map.put("name", "Name: " + XMLfunctions.getValue(e, "name"));
Drawable d = dManager
.fetchDrawable("http://MY_WEBSITE/images/"
+ XMLfunctions.getValue(e, "image"));
map.put("image", d);
map.put("imageUrl", XMLfunctions.getValue(e, "image"));
mylist.add(map);
}
ListAdapter adapter = new SimpleAdapter(this, mylist,
R.layout.products, new String[] { "image", "name", "id", },
new int[] { R.id.item_image, R.id.item_title,
R.id.item_subtitle });
setListAdapter(adapter);
final ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
@SuppressWarnings("unchecked")
HashMap<String, Object> o = (HashMap<String, Object>) lv
.getItemAtPosition(position);
//Toast.makeText(productsActivity.this, "ID '" + o.get("id") +
//"' was clicked.", Toast.LENGTH_LONG).show();
Drawable d = dManager
.fetchDrawable("http://MY_WEBSITE/images/"
+ o.get("imageUrl"));
ImageView imgView = (ImageView) view
.findViewById(R.id.item_image);
o.put("image", d);
imgView.setImageDrawable(d);
}
});