我的光标从sqlite获取3列数据,第1列是食谱名称,第2列是食谱作者,第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。如何让它显示来自互联网的图片?
答案 0 :(得分:0)
本讨论中答案下方的帖子可能对您有用:
答案 1 :(得分: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
}