开发者

Unable to set image into ImageView from a ListView using SimpleAdapter, ViewBinder and Asynctask

I have a problem. I'm trying to retrieve an image from a online source and the set the image into the ListView's ImageView. However, I can't do that because I can't link my ImageView within the 开发者_开发技巧ListView as it returns a NullPointerException. I realise that I have to use VieWBinder to set the image into the ImageView within the ListView.

Currently, I'm using the ImageLoader class from here as well as the ViewBinder class from here.

This is my ViewBinder Class:

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 is a class where I got the listData from which contains data like the url to the images. How can I do use the ImageLoader class to insert the downloaded image into the ImageView within the ListView using ViewBinder?

*Side Note: It would give me an error "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 " as well *


Set tag for the image view say for instance the URL of the image. And in your onPostExecute fetch the image view by list view.findViewByTag. I don't agree using asynctask for fetching images as there would be many asynctask if your list view is having lot of list items.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜