2

我有个问题。我正在尝试从在线资源中检索图像并将图像设置为ListView. ImageView但是,我不能这样做,因为我无法在其中链接我ImageView的,ListView因为它返回一个NullPointerException. 我意识到我必须使用VieWBinder将图像设置ImageViewListView.
目前,我正在使用这里ImageLoader的课程以及这里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该类将下载的图像插入到ImageViewusingListViewViewBinder

*旁注:它会给我一个错误“05-12 13:16:37.195: INFO/System.out(736): resolveUri failed on bad bitmap uri: http://lib.syndetics.com/index.aspx? isbn=9780137081851/SC.GIF&client=tpoly&type=xw12 " 以及*

4

1 回答 1

0

为图像视图设置标签,例如图像的 URL。并在您的 onPostExecute 中通过 list view.findViewByTag 获取图像视图。我不同意使用 asynctask 来获取图像,因为如果您的列表视图有很多列表项,那么会有很多 asynctask。

于 2012-09-19T12:56:25.193 回答