android - Live Update ListView -


i have dug deep down but, although have found other people asking similar questions mine, have not yet find question addresses same issues have. have not found satisfying answer either.

i have listview. when call adapter, .notifydatasetchanged, listview updated, can see update once onresume() called. in other words, not see instantly, after leave activity , comeback.

what can see update instantly? have tried .notifydatasetchanged method, have tried resetting adapter... nothing worked.

according comment, dont update array in adapter, array held activity passed adapter once. thats why adapter isnt updating properly. changing array outside of adapter-class, might not same array-object adapter using. @ onresume(), adapter recreated new array , showing new content.

a solution using following custom adapter class:

class myadapter extends baseadapter {      private array[] myarray;      public myadapter(array[] myarray) {         this.myarray = myarray;     }      public updatecontent(array[] mynewarray) {         this.myarray = mynewarray;         this.notifydatasetchanged();     }      // getitem, getview, , on methods  } 

then activity, simple call myarray.updatecontent() new array , update immediatly.


its never hold , manipulate object used 1 class (the adapter) within 1 (the activity). try move code manipulating array adapter , use methods add/remove items. make lot easier finding kind of errors!


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -