android - How to fetch and set data in listview adapter using background thread? -




i have app contain listview list of installed apps in device , set adaptor problem freezes app second when getting list of apps installed in device. want these list , set adapter using background thread.how do that

code:-

asynctask.execute(new runnable() {         @override         public void run() {             final list<cwhitelistappsmodel> installedapps = getinstalledapps();             getactivity().runonuithread(new runnable() {                 @override                 public void run() {                     installedappadapter = new cwhitelistappsadapter(mcontext, installedapps, cwhitelistappsfragment.this);                     appcount();                     userinstalledapps.setadapter(installedappadapter);                 }             });          }     }); 

try implement asynctask inner class
this show progressdialoginstead of shwing app hanged, hope helps!

 private class yourasynctask extends asynctask<string, string, arraylist<yourclass>> {          progressdialog progressdialog;         @override         protected void onpreexecute() {             // start loading animation maybe?             progressdialog = progressdialog.show(dictionarysscwords.this,                     "appname",                     "loading....");         }      @override     protected arraylist<yourclass> doinbackground(string... params) {        //fetch database here         return temp;       }      @override     protected void onpostexecute(arraylist<yourclass> yourclass) {         progressdialog.dismiss();          //update list view here         list.setadapter(new myadapter(yourclass));     } } 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -