Android - GridView forcing update on data change -


i've implemented sample (2. custom adapter example) http://www.mkyong.com/android/android-gridview-example/ , works.

i wanted "refresh" data new set, didn't work until did this:

imageadapter.notifydatasetchanged(); 

and removed following check in imageadapter getview method :

 if (convertview == null) { 

here current getview method

public view getview(int position, view convertview, viewgroup parent) {      layoutinflater inflater = (layoutinflater) context             .getsystemservice(context.layout_inflater_service);      view gridview;      // if (convertview == null) {  // stopped gridview updating !!     if (true)     {         gridview = new view(context);          // layout mobile.xml         gridview = inflater.inflate(r.layout.mobile, null);          // set value textview         textview textview = (textview) gridview                 .findviewbyid(r.id.grid_item_label);          textview.settext(mobilevalues[position]);           // set image based on selected text         imageview imageview = (imageview) gridview                 .findviewbyid(r.id.grid_item_image);          imageview.setimageresource(r.drawable.square);       } else {         gridview = (view) convertview;     }      return gridview; } 

i'm concerned doing unnecessary processing on , on - i.e. inflating view multiple times?

should creating new gridview every time called ?

it didn't work because following rows

   textview textview = (textview) gridview             .findviewbyid(r.id.grid_item_label);      textview.settext(mobilevalues[position]);       // set image based on selected text     imageview imageview = (imageview) gridview             .findviewbyid(r.id.grid_item_image);      imageview.setimageresource(r.drawable.square); 

go outside if/else. check if (convertview == null) necessary. if don't have inflate n different views, n == getcount(). n large problem. , want implement android viewholder pattern, give users best ux possible.

as correctly pointed out @vzsg, rid of gridview = new view(context);. additional useless allocation


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -