listview - Android Custom list loads very slow -


made custom list view includes image, 2 text views , checkbox. identify checkbox being checked/ unchecked, problem design slow scrolling. faster if test real device.

public class listviewactivity extends listactivity {   protected void oncreate(bundle savedinstancestate) {     // todo auto-generated method stub     super.oncreate(savedinstancestate);     arrayadapter<model> compositeadapter = new compositeadapter(this,             getmodel());     setlistadapter(compositeadapter);     listview lv = getlistview();     lv.setfastscrollenabled(true);    } }  private class compositeadapter extends arrayadapter<model> {     private final list<model> list;     private final activity context;      public compositeadapter(activity context, list<model> list) {         super(context, r.layout.listviewactivitylayout, list);         this.context = context;         this.list = list;     }      private class viewholder{         protected textview textview1;         protected textview textview2;         protected imageview imageview;         protected checkbox ckbox;     }     public view getview (int position, view convertview, viewgroup parent) {         view view = null;         final viewholder vh;         if(convertview==null){             layoutinflater li = context.getlayoutinflater();             view = li.inflate(r.layout.listviewactivitylayout, null);              vh = new viewholder();             vh.ckbox =(checkbox) view.findviewbyid(r.id.list_view_layout_checkbox);             vh.imageview = (imageview) view.findviewbyid(r.id.listview_image_view);             vh.textview1 = (textview)view.findviewbyid(r.id.list_view_layout_text_view1);             vh.textview2= (textview)view.findviewbyid(r.id.list_view_text_view2);             view.settag(vh);         }         else{             view= convertview;             vh = (viewholder)view.gettag();         }  /** ** sending text , images each of list view ** */ 

you loading images. needs handled in seperate thread , placed on imageview when decoded.

here excelent project that. lazy load images

edit

by looking @ code there few things noticing:

first: there isnt place asigning picture. (use lazy loading adapter that)

second: checkbox selections messed up. need keep track of checked position state , redraw in getview (hashmap or better sparse array that)

third rid of helper view using. don't need it. (it market view view in code).

so, if convertview==null use convertview=inflate... , return 1 @ end.

and fourth useful tip: move adapter class new class java file. keeping activity reference , list, can reduce amount of code in activity.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -