2012-01-20 48 views
0

我的光标从sqlite获取3列数据,第1列是配方名称,第2列是配方作者,第3列是配方图像的URL。这里是我的代码的一部分listview从互联网和来自sqlite的数据显示图像

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。我怎样才能让它从互联网上显示图片呢?

回答

0

的帖子在讨论正确的答案下面可能是你有帮助:

Lazy load of images in ListView

+0

其实我以前也一直在看lazylist的帖子,但还没有时间修改它以适应我的问题..但我想我应该花更多的时间看它,然后呢 – imin

0

你需要一个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 

} 
相关问题