Display Image In Listview Using Simpleadapter Android
I am currently working on an android application displaying image into my listview using SimpleAdapter. My image is retrieved from my online server. After i retrieve the image, i t
Solution 1:
The problem is here:
map.put(TAG_PHOTO, d.toString());
You set that key to a string like "Drawable@0x12345678"
and then bind it to R.id.list_image
which I assume is an ImageView. That won't work.
I haven't used a Drawable quite like that, but I have had success with a Bitmap:
Bitmap bitmap = BitmapFactory.decodeStream(is);
And then I overrode bindView
on my Adapter to set the image:
publicvoidbindView(View view, Context context, Cursor cursor) {
// do the default stuffsuper.bindView(view, context, cursor);
// now set the imageImageViewimgView= (ImageView) view.findViewById(R.id.imageView1);
imgView.setImageBitmap(bitmap);
}
A SimpleAdapter
doesn't have a bindView
method, so instead you can provide a ViewBinder
:
mySimpleAdapter.setViewBinder(newSimpleAdapter.ViewBinder() {
@OverridepublicbooleansetViewValue(View view, Object data, String textRepresentation) {
if (view.getId().equals(R.id.my_img_view_id)) {
((ImageView) view).setImageBitmap(bitmap);
// we have successfully bound this viewreturntrue;
} else {
// allow default binding to occurreturnfalse;
}
}
});
Post a Comment for "Display Image In Listview Using Simpleadapter Android"