简体   繁体   English

无法使用SimpleAdapter,ViewBinder和Asynctask从ListView将图像设置为ImageView

[英]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 . 我正在尝试从在线资源中检索图像并将图像设置为ListViewImageView However, I can't do that because I can't link my ImageView within the ListView as it returns a NullPointerException . 但是,我不能这样做,因为我无法在ListView内链接ImageView ,因为它返回了NullPointerException I realise that I have to use VieWBinder to set the image into the ImageView within the ListView . 我意识到我必须使用VieWBinder将图像设置为ListView内的ImageView
Currently, I'm using the ImageLoader class from here as well as the ViewBinder class from here . 目前,我使用ImageLoader从类这里还有ViewBinder从类在这里
This is my ViewBinder Class: 这是我的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 is a class where I got the listData from which contains data like the url to the images. SearchResults是我从中获取listData的类,其中包含像图像的url这样的数据。 How can I do use the ImageLoader class to insert the downloaded image into the ImageView within the ListView using ViewBinder ? 我该怎么办使用ImageLoader类来下载的图像插入ImageView的内ListView使用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 * *旁注:这会给我一个错误“ 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 “以及*

Set tag for the image view say for instance the URL of the image. 设置图像视图的标签,例如说图像的URL。 And in your onPostExecute fetch the image view by list view.findViewByTag. 并在您的onPostExecute中通过列表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. 我不同意使用asynctask来获取图像,因为如果您的列表视图中有很多列表项,那么将会有很多asynctask。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM