android-ImageView in listview not showing image when scroll up and down -
i'm getting images internet via universalimagedownloader , i'm using viewholder showing them :
public class listadapter2 extends baseadapter { activity activity; public arraylist<hashmap<string, string>> list; public listadapter2(activity activity, arraylist<hashmap<string, string>> list) { super(); this.activity = getactivity(); this.list = list; } public hashmap<string, string> geting(int position) { return list.get(position); } public void addall(arraylist<hashmap<string, string>> result) { if (this.list == null) { this.list = result; } else { this.list.addall(result); } notifydatasetchanged(); } public int getcount() { return list.size(); } public object getitem(int position) { return list.get(position); } public long getitemid(int arg0) { return 0; } private class viewholder { imageview img; } public view getview(int position, view convertview, viewgroup parent) { final viewholder holder; layoutinflater inflater = activity.getlayoutinflater(); if (convertview == null) { convertview = inflater.inflate(r.layout.row_grids, null); holder = new viewholder(); holder.img = (imageview) convertview.findviewbyid(r.id.image); convertview.settag(holder); } else { holder = (viewholder) convertview.gettag(); } item = list.get(position); if(item.get("img").length()>0) imageloader.displayimage("http://website.com/img/" + item.get("img"), holder.img, options, imagelistener); else holder.img.setimagedrawable(getresources().getdrawable(r.drawable.fix)); } return convertview; } public void clear() { if (this.list.size() > 0) this.list.clear(); } } private static class imagedisplaylistener extends simpleimageloadinglistener { static final list<string> displayedimages = collections.synchronizedlist(new linkedlist<string>()); @override public void onloadingcomplete(string imageuri, view view, bitmap loadedimage) { if (loadedimage != null) { imageview imageview = (imageview) view; boolean firstdisplay = !displayedimages.contains(imageuri); if (firstdisplay) { fadeinbitmapdisplayer.animate(imageview, 500); displayedimages.add(imageuri); } } } }
i've tested 3 phones , works fine when test on friends't phone, times 1 of images not showing .
for example, when come activity , shows images , when scroll down last items not showing anymore , scroll up, 1 of images that's been showing before not showing anymore , shows default image .
is there wrong code ? way, i've 4 tabs , happens in tabs .
thanks
the problem displayimage method, not encode url cases ..the better approch should use picasso library
if using android studio add
compile 'com.squareup.picasso:picasso:2.5.2'
in build.gradle file , sync:
or else picasso site download jar file eclipse
after able use picasso library , replace lines
if(item.get("img").length()>0) imageloader.displayimage("http://website.com/img/" + item.get("img"), holder.img, options, imagelistener); else holder.img.setimagedrawable(getresources().getdrawable(r.drawable.fix)); } string imgurl = "http://website.com/img/" + item.get("img"); if (!imgurl.equals("")) picasso.with(activity).load(imgurl).into(holder.img); else picasso.with(activity).load(r.drawable.fix).into(holder.img );
Comments
Post a Comment