android - GridView stays empty -


i have gridview 1 imageview , 1 textview below in each cell.

the logic works well. make reference gridview, set columns , set adapter. during have thread set's images , name list. (one drawable list images , 1 string list labels). satisfy users, want update gridview while thread adding images , labels lists.

but update works if provide nasty static variables. (i hate them). or if set adapter new gridview everytime update has occured. (this nasty because not able scroll gridview during ist update..)

this customadapter:

public customadapter(dialogbox dialogboxactivity,list<drawable> imported_scaled_images, list<string> imported_labels, int position) {     this.context = dialogboxactivity;     this.scaledimage = imported_scaled_images.toarray(new drawable[imported_scaled_images.size()]);     this.labels = imported_labels.toarray(new string[imported_labels.size()]);     this.used_cells = position;     inflater = (layoutinflater) context.getsystemservice(context.layout_inflater_service);  }  public void updategrid(list<drawable> imported_scaled_images, list<string> imported_labels, int position) {     this.scaledimage = imported_scaled_images.toarray(new drawable[imported_scaled_images.size()]);     this.labels = imported_labels.toarray(new string[imported_labels.size()]);     this.used_cells = position;     this.notifydatasetchanged();     log.e("update","true"); }  @override public void notifydatasetchanged() {     // todo auto-generated method stub     super.notifydatasetchanged();     log.e("notify","true"); }  @override public int getcount() {     // todo auto-generated method stub     return used_cells; }  @override public object getitem(int position) {     // todo auto-generated method stub     return position; }  @override public long getitemid(int position) {     // todo auto-generated method stub     return position; }  public class holder {      imageview img;     textview tv;      public holder(imageview img, textview tv) {         this.img = img;         this.tv = tv;     } }   @override public view getview(final int position, view convertview, viewgroup parent) {     // todo auto-generated method stub     imageview img;     textview tv;     textview tv_abc;      if(convertview == null) {         convertview = inflater.inflate(r.layout.customadapter_view_layout, null);         img = (imageview) convertview.findviewbyid(r.id.img);         tv =(textview) convertview.findviewbyid(r.id.tv);         //tv_abc = (textview) convertview.findviewbyid(r.id.tv_normal_portrait_abc);         convertview.settag(new holder(img,tv));     } else {         holder holder = (holder) convertview.gettag();         img = holder.img;         tv = holder.tv;         //tv_abc = holder.tv_abc;      }             img.setimagedrawable(scaledimage[position]);             tv.settext(labels[position]);             notifydatasetchanged();     return convertview; } 

}

and on activity have updategrid , call in timertask on mainthread:

private void updategrid() {     customadapter.updategrid(images, labels, position); } 

what's happening gridview stays empty. maybe it's because position 0 while im setting baseadapter gridview. can't problem because when i'm updating should recognize new size in getcount(). once again, logic works well. images added , methods updategrid , notiydatasetchanged called want to. gridview stays like, don't showing these images.(completely empty).

hope can provide solution. appreciate every , every improvement of code posted above.(regarding performance or whatever). thank you!

update: position variable counts cells available. because cells empty(=null). due don't know how cells filled(because sort images alphabetically(for each row => cells filled null) can't provide baseadapters getcount method number before logic hasn't finished)

getcount return total no item count not position :

@override public int getcount() {     return imported_scaled_images.size(); } 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -