开发者

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

开发者 https://www.devze.com 2023-01-24 02:17 出处:网络
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.

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

精彩评论

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

关注公众号