【发布时间】:2012-01-25 21:36:13
【问题描述】:
是否可以在同一个 HashMap 中将字符串和可绘制对象作为对象传递,然后使用此 hashmap 通过 SimpleAdapter 填充 ListView ?
我想要这个,因为我首先获得了 JSON 数据,其中还包含缩略图的 URL。然后我下载这个缩略图。相关代码(我认为):
for (...) {
...
InputStream is = (InputStream)content;
Drawable image = Drawable.createFromStream(is, "src");
// Hashmap
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("title", new String(jsonObject.getString("Title")));
map.put("thumb", image);
mylist.add(map);
}
ListAdapter adapter = new SimpleAdapter(getActivity(), mylist, R.layout.listitem,
new String[] { "title", "thumb"},
new int[] { R.id.title, R.id.thumb });
setListAdapter(adapter);
R.id.title = TextView,R.id.thumb = ImageView
这适用于标题字符串,但不适用于可绘制对象。这种做法是不是很愚蠢?
提前致谢。
【问题讨论】:
标签: android listview hashmap listadapter