我有一个问题。我正在尝试从在线资源中检索图像并将图像设置到 ListView
的 ImageView
中。但是,我不能这样做,因为我无法在 ListView
中链接我的 ImageView
,因为它返回一个 NullPointerException
。我意识到我必须使用 VieWBinder
将图像设置到 ListView
中的 ImageView
中。
目前,我正在使用 here 中的 ImageLoader
类以及来自 here 的 ViewBinder
类.
这是我的 ViewBinder 类:
SearchResults sr = new SearchResults();
ImageDownloader imageDownloader = new ImageDownloader();
@Override
public boolean setViewValue(View view, Object data, String textRepresentation) {
if (view instanceof ImageView && data instanceof Bitmap) {
// TODO Auto-generated method stub
for (int i = 0; i < sr.listData.size(); i++) {
String imageISBN = sr.listData.get(i).get("coverImage");
ImageView iv = (ImageView) view;
Bitmap bm = (Bitmap) data;
imageDownloader.download(imageISBN,iv);
//iv.setImageBitmap(bm);
return true;
}
}
return false;
}
SearchResults
是我从中获取 listData 的类,其中包含图像 url 等数据。我怎样才能使用 ImageLoader
类使用 ViewBinder
将下载的图像插入到 ListView
中的 ImageView
中?
*旁注:它会给我一个错误“05-12 13:16:37.195: INFO/System.out(736): resolveUri在错误的位图 uri 上失败:http://lib.syndetics.com/index.aspx?isbn=9780137081851/SC.GIF&client=tpoly&type=xw12 "还有 *
最佳答案
为 ImageView 设置标签,例如图像的 URL。并在您的 onPostExecute 中通过列表 view.findViewByTag 获取 ImageView 。我不同意使用 asynctask 来获取图像,因为如果您的 ListView 有很多列表项,那么会有很多 asynctask。
关于android - 无法使用 SimpleAdapter、ViewBinder 和 Asynctask 将图像从 ListView 设置到 ImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5974037/