【发布时间】:2012-12-28 20:55:29
【问题描述】:
我有带有位图和文本的列表视图。当我下载图片并想查看它时,它不会出现在我的应用程序中。当我使用来自 R.drawable.imagename 的图像时,它可以工作...... 我的代码:
List<HashMap<String, Object> > aList = new ArrayList<HashMap<String, Object> >();
for(int i=0;i<ilosctalentow.size();i++){
if (ilosctalentow.get(i).indexOf("0/")==-1)
{
HashMap<String, Object> hm = new HashMap<String,Object>();
hm.put("txt", "xxx");
hm.put("cur","Currency : " + ilosctalentow.get(i));
Bitmap bmp = DownloadImage("http://www.xxx.pl/xxx/xxx/xhxuxj.png");
hm.put("flag",bmp);
aList.add(hm);
Log.i(TAG,Integer.toString(R.drawable.afghanistan) );
}
}
// Keys used in Hashmap
String[] from = { "flag","txt","cur" };
// Ids of views in listview_layout
int[] to = { R.id.flag,R.id.txt,R.id.cur};
// Instantiating an adapter to store each items
// R.layout.listview_layout defines the layout of each item
SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), aList, R.layout.listview_layout, from, to);
// Getting a reference to listview of main.xml layout file
ListView listView = ( ListView ) findViewById(R.id.listview);
// Setting the adapter to the listView Zaraz mnie huj strzeli
listView.setAdapter(adapter);
请帮忙!
【问题讨论】:
-
我怀疑是否可以从 UI 线程下载图像。您应该在后台线程中下载图像并在下载完成后更新适配器。另外我认为有必要创建自己的适配器而不是 SimpleAdapter 类。
-
可以用绿色机器人制作吗?
-
任何版本的 Android 都可以。这是著名的问题,您可以在那里找到代码示例:stackoverflow.com/questions/541966/…
-
@vorrtex:有可能,但这是个非常糟糕的主意..
-
@K-ballo 您在链接所指的页面上发布的所有启示。也许您可以在最佳答案中得分并说服所有人他们错了。
标签: java android image listview bitmap