java - Adapter behaviour when loading image from URL ion library -


i m facing problem when want load images adapter using ion library.

in fact, have items string corresponding url of iconic image want load each item on gridview.

the problem due adapter view management (reusing existing view if m not wrong), , dont know how bypass this...

for example, if load 10 elements image, first time works. then, when scroll bottom, , scroll top, image changes (due reuse of existing view...)

can me ?

this adapter code :

public class protocoleadapter extends baseadapter {     private context context;     private list<protocoleitem> mliste;      public protocoleadapter(context context, list<protocoleitem> liste) {         this.context = context;         this.mliste = liste;     }      private class viewholder {         textview txttitre;         imageview img;      }      public view getview(int position, view convertview, viewgroup parent) {          viewholder holder = null;          layoutinflater minflater = (layoutinflater) context                 .getsystemservice(activity.layout_inflater_service);         if (convertview == null) {             convertview = minflater                     .inflate(r.layout.grid_item, null);              holder = new viewholder();              holder.txttitre = (textview) convertview                     .findviewbyid(r.id.grid_item_label);              holder.img = (imageview) convertview                     .findviewbyid(r.id.grid_item_image);               convertview.settag(holder);         } else {             holder = (viewholder) convertview.gettag();         }          final protocoleitem rowitem = mliste.get(position);           boolean isloaded = false;         try {             bitmap bitmap = ion.with(context)                     .load(rowitem.getimage())                     .asbitmap()                     .get();              isloaded = true;              holder.img.setimagebitmap(bitmap);          } catch (interruptedexception e) {             e.printstacktrace();         } catch (executionexception e) {             e.printstacktrace();         }          if (!isloaded) {             if (position % 5 == 0) {                 holder.img.setbackgroundcolor(0xff176799);             } else {                 if (position % 4 == 0) {                     holder.img.setbackgroundcolor(0xff2f87b0);                 } else {                     if (position % 3 == 0) {                         holder.img.setbackgroundcolor(0xff42a4bb);                     } else {                         if (position % 2 == 0) {                             holder.img.setbackgroundcolor(0xff5bc0c4);                         } else {                             holder.img.setbackgroundcolor(0xff78d6c7);                         }                     }                 }             }         }          holder.txttitre.settext(rowitem.gettitre());           return convertview;     } 

thanks !

have day

get latest version of ion , use following.

ion.with(holder.img) .load(rowitem.getimage()); 

this method load asynchronously.

your current usage blocking ui thread. ion should handle convertview recycling, not issue.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -