【问题标题】:Unable to set image into ImageView from a ListView using SimpleAdapter, ViewBinder and Asynctask无法使用 SimpleAdapter、ViewBinder 和 Asynctask 从 ListView 将图像设置为 ImageView
【发布时间】:2011-08-23 20:39:57
【问题描述】:

我有问题。我正在尝试从在线资源中检索图像并将图像设置为ListViewImageView。但是,我不能这样做,因为我无法在ListView 中链接我的ImageView,因为它返回NullPointerException。我意识到我必须使用VieWBinder 将图像设置到ListView 内的ImageView
目前,我正在使用来自hereImageLoader 类以及来自hereViewBinder 类。
这是我的 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 类将下载的图像插入ListView 内的ImageView 中使用ViewBinder

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

【问题讨论】:

    标签: android android-listview android-asynctask android-imageview android-viewbinder


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-12-28
      • 1970-01-01
      • 2023-03-29
      • 2013-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多