android - How to use asyncTask to load images from resources -


here in custom adapter, in list view there 1 imageview. loading list of images in listview. want load new images in asynctask idont know how implement asynctask , tutorials refers image downloading using drawable resources, kindly guide me through how implement asynchronous loading of images replace image in current visible view.

class myadapter extends baseadapter {      private context context;     private int images[];      public myadapter(context context, int images[]) {         this.context = context;         this.images = images;     }      @override     public int getcount() {         // todo auto-generated method stub         return images.length;     }      @override     public object getitem(int position) {         // todo auto-generated method stub         return images[position];     }      @override     public long getitemid(int position) {         // todo auto-generated method stub         return position;     }      class myviewholder {         imageview imageview;          public myviewholder(view v) {             // todo auto-generated constructor stub             imageview = (imageview) v.findviewbyid(r.id.imgview);         }     }      @override     public view getview(int position, view convertview, viewgroup parent) {         // todo auto-generated method stub         view row = convertview;         myviewholder holder = null;         if (row == null) {             layoutinflater inflater = (layoutinflater) context                     .getsystemservice(context.layout_inflater_service);             row = inflater.inflate(r.layout.custom_list, parent, false);              holder = new myviewholder(row);             row.settag(holder);         } else {             holder = (myviewholder) row.gettag();             row = convertview;         }         holder.imageview.setimageresource(images[position]);         return row;     } } 

and here mainactivity calling myadapter list of images.

public class mainactivity extends activity {      private listview listview;     private myadapter myadapter;      int[] images = { r.drawable.img001, r.drawable.img002, r.drawable.img003,             r.drawable.img004, r.drawable.img005, r.drawable.img006,             r.drawable.img007, r.drawable.img008, r.drawable.img009,             r.drawable.img010, r.drawable.img011, r.drawable.img012,             r.drawable.img013, r.drawable.img014, r.drawable.img015,             r.drawable.img016, r.drawable.img017, r.drawable.img018,             r.drawable.img019, r.drawable.img020, r.drawable.img021,             r.drawable.img022, r.drawable.img023, r.drawable.img024,             r.drawable.img025, r.drawable.img026, r.drawable.img027,             r.drawable.img028, r.drawable.img029, r.drawable.img030,             r.drawable.img031, r.drawable.img032, r.drawable.img033,             r.drawable.img034, r.drawable.img035, r.drawable.img036,             r.drawable.img037, r.drawable.img038, r.drawable.img039,             r.drawable.img040, r.drawable.img041, r.drawable.img042,             r.drawable.img043, r.drawable.img044, r.drawable.img045,             r.drawable.img046, r.drawable.img047, r.drawable.img048,             r.drawable.img049, r.drawable.img050, r.drawable.img051,             r.drawable.img052, r.drawable.img053, r.drawable.img054,             r.drawable.img055, r.drawable.img056, r.drawable.img057,             r.drawable.img058, r.drawable.img059, r.drawable.img060,             r.drawable.img061, r.drawable.img062, r.drawable.img063,             r.drawable.img064, r.drawable.img065, r.drawable.img066,             r.drawable.img067, r.drawable.img068, r.drawable.img069,             r.drawable.img070, r.drawable.img071, r.drawable.img072,             r.drawable.img073, r.drawable.img074, r.drawable.img075,             r.drawable.img076, r.drawable.img077, r.drawable.img078,             r.drawable.img079, r.drawable.img080, r.drawable.img081,             r.drawable.img082, r.drawable.img083, r.drawable.img084,             r.drawable.img085, r.drawable.img086, r.drawable.img087,             r.drawable.img088, r.drawable.img089, r.drawable.img090,             r.drawable.img091, r.drawable.img092, r.drawable.img093,             r.drawable.img094, r.drawable.img095, r.drawable.img096,             r.drawable.img097, r.drawable.img098, r.drawable.img099,             r.drawable.img100 };      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);              myadapter = new myadapter(this, images);         listview = (listview) findviewbyid(r.id.imglist);         listview.setadapter(myadapter);     }   } 

dependencies {     compile 'com.squareup.picasso:picasso:2.3.2' }  picasso.with(context).load(r.drawable.<id>).into(holder.imageview); 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -