开发者

How to show images loaded from DB into a listView in Android

I populate a ListView from the result of a SQLite query. One of the fields is the image file name that I would like to show as an i开发者_如何学Pythonmage into a ListView. How can I do to show the image file? I use:

SimpleCursorAdapter(this, R.layout.list_name,cur,new String[] {"fields_list"}, new int[] { R.id.list...});

Thanks in advance.


Not the complete solution, but I think this should get you started

public class ImageBlobViewBinder implements SimpleCursorAdapter.ViewBinder { 
    public boolean setViewValue(View view, Cursor cursor, int columnIndex) {

        if (columnIndex == IMAGE_DATA_INDEX) { 
            byte[] bitmap = cursor.getBlob(cursor.getColumnIndex("image_data"));
            Bitmap myImage = BitmapFactory.decodeByteArray(bitmap, 0, bitmap.length);
            ((ImageView) view).setImageResource(myImage); 
            return true; 
        }

        return false; 
    } 
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜