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;
}
}
精彩评论