我有一个SimpleAdapter如下:
ListAdapter adapter = new SimpleAdapter(
ItemDetail.this, itemList,
R.layout.list_item, new String[]{
TAG_PID,
TAG_NAME,
TAG_PICTURE
},
new int[]{
R.id.pid,
R.id.name,
R.id.img
});
setListAdapter(adapter);
但图像存在问题。我的图片需要从网址获取。我可以通过这段代码得到它们:
try {
final String imageUrl = "http://example.com/pic/jpg";
InputStream in = (InputStream) new URL(imageUrl).getContent();
Bitmap bitmap = BitmapFactory.decodeStream(in);
in.close();
} catch (Exception e) {
e.printStackTrace();
}
最后设置图片:
ImageView image = (ImageView) findViewById(R.id.img);
//img is a single item in a list_item xml file
image.setImageBitmap(bitmap);
但我的问题是,如何合并以上所有代码?下载并设置列表中每个项目的图像。