imageview - Android image loading in listview -
in android application asyntask used loading images web in list view.i want show center portion of image , have tried imageloader loading images problem image clarity poor have used loading thumbnails because thumbnail small.so have tried asyntask given below.the problem method image view shows other images means image view in first list item show next list item's image , after time display correct image.how can solve issue.or suggest method lading images clarity.please me.thanks in advance
private class downloadimagetask extends asynctask<string, void, bitmap> { imageview bmimage; progressbar mprogressbar; string url; public downloadimagetask(imageview bmimage, progressbar progressbar) { this.bmimage = bmimage; this.mprogressbar = progressbar; } @override protected void onpreexecute() { mprogressbar.setvisibility(view.visible); super.onpreexecute(); } protected bitmap doinbackground(string... urls) { string urldisplay = urls[0]; url = urldisplay; bitmap micon11 = null; try { inputstream in = new java.net.url(urldisplay).openstream(); micon11 = bitmapfactory.decodestream(in); } catch (exception e) { // log.e("error", e.getmessage()); e.printstacktrace(); } return micon11; } protected void onpostexecute(bitmap result) { utilities.addbitmaptomemorycache(url, result); bmimage.setimagebitmap(result); mprogressbar.setvisibility(view.gone); // result.recycle(); } }
}
public view getview(final int position, view convertview, viewgroup parent) { vi = convertview; int type = getitemviewtype(position); // utilities.message_player = new mediaplayer(); if (vi == null) { inflater = layoutinflater.from(mcontext); if (type == item_type_one) vi = inflater.inflate(r.layout.message_group_list_item, null); else vi = inflater.inflate(r.layout.listlastrow, null); } if (type == item_type_one) { if (fonttype == true) { } ((imageview) vi.findviewbyid(r.id.imagemessage)).settag(position+"i"); bitmap bmp = utilities.getbitmapfrommemcache(feedsimage); if(bmp == null){ downloadimagetask dwnloadimgtask = new downloadimagetask(((imageview) vi.findviewwithtag(position+"i")), ((progressbar) vi.findviewbyid(r.id.progressbar1))); dwnloadimgtask.execute(feedsimage); }else{ ((imageview) vi.findviewbyid(r.id.imagemessage)).setimagebitmap(bmp); } } }
when setting bitmap cache or downloading new image, missing :
your parent view (vi) possibly created view recycled avoid recreating each views (that convertview for).
this convertview has image on since it's recycled item image has been loaded.
so have reset image view content in case you've got convertview :
((imageview) vi.findviewbyid(r.id.imagemessage)).settag(position+"i"); bitmap bmp = utilities.getbitmapfrommemcache(feedsimage); if(bmp == null){ //here add line reset bitmap of imageview ((imageview) vi.findviewbyid(r.id.imagemessage)).setimagebitmap(null); downloadimagetask dwnloadimgtask = new downloadimagetask(((imageview) vi.findviewwithtag(position+"i")), ((progressbar) vi.findviewbyid(r.id.progressbar1))); dwnloadimgtask.execute(feedsimage); }else{ ((imageview) vi.findviewbyid(r.id.imagemessage)).setimagebitmap(bmp); }
i've set null
remove bitmap, want set placeholder bitmap ( grey picture reload icon on or similar... )
hope helps.
Comments
Post a Comment