【问题标题】:listview display images from internet and data from sqlitelistview 显示来自互联网的图像和来自 sqlite 的数据
【发布时间】:2012-01-20 08:22:39
【问题描述】:

我的光标从 sqlite 获取 3 列数据,第一列是配方名称,第二列是配方作者,第三列是配方图像的 url。这是我的一部分代码

private static final String fields[] = { "recipeID", "recipeName", "thumbnail"};
Cursor mCursor = dbAdapter.getAllTitles(); //get all titles returns the recipe name, author and thumbs
startManagingCursor(mCursor);
dataSource = new SimpleCursorAdapter(this, R.layout.recipelist, mCursor, fields,    
                  new int[] { R.id.recipeAuthor, R.id.recipeName, R.id.recipeThumb });
setListAdapter(dataSource);

显然,上面的代码没有显示食谱图像,而是仅在 R.id.recipeThumb 显示食谱图像的 url。我怎样才能让它显示来自互联网的图片呢?

【问题讨论】:

    标签: android listview


    【解决方案1】:

    此讨论中答案正下方的帖子可能对您有用:

    Lazy load of images in ListView

    【讨论】:

    • 其实我之前也一直在看lazylist的帖子,但是没有时间修改它以适应我的问题..但我想我应该花更多的时间看它
    【解决方案2】:

    您需要一个 CustomAdapter 并覆盖 getView() 方法。 在基于 Url 的 getView() 方法中创建一个 ImageView。

    getView(...) {
       //First Create a Drawable from the InputStream of the Url 
       //store this drawable locally so that you don't have to fetch it again 
       Drawable imgDrawable = Drawable.createFromStream(inputStream,"");
       //set this in the imageView
       imgView.setImageDrawable(imgDrawable);
    
       //set this imgView in the contentview and return
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-08
      • 1970-01-01
      • 2012-03-20
      • 2016-11-23
      • 2020-08-02
      • 2015-05-25
      • 1970-01-01
      • 2012-10-16
      相关资源
      最近更新 更多