android - using AsyncTask with firebase -


my application retrieve data firebase ,this takes time depending on user's internet speed

i want make progress dialog appear until data loaded firebase using "asynctask"

public class mainactivity extends navigationapp { private recyclerview recyclerview; private databasereference myref ; private static context context;   @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     backgroundtask task = new backgroundtask(mainactivity.this);     task.execute();      layoutinflater inflater = (layoutinflater) this.getsystemservice(context.layout_inflater_service);     //inflate activity layout here!     view contentview = inflater.inflate(r.layout.activity_main, null, false);     drawer.addview(contentview, 0);       firebase.setandroidcontext(this);     recyclerview=(recyclerview)findviewbyid(r.id.recyclerview);     recyclerview.sethasfixedsize(true);     recyclerview.setlayoutmanager(new linearlayoutmanager(this));     myref= firebasedatabase.getinstance().getreference().child("/detail/");      firebaserecycleradapter<detail,detailviewholder> recycleradapter=new   firebaserecycleradapter<detail,detailviewholder>(             detail.class,             r.layout.individual_row,             detailviewholder.class,             myref     ) {  @override     protected void populateviewholder(detailviewholder viewholder, detail model, final int position) {     viewholder.settitle(model.gettitle());     viewholder.setdescription(model.getdescription());     viewholder.mview.setonclicklistener(new view.onclicklistener() {     @override     public void onclick(view view) {   final intent intent;     switch (position){     case 0:       intent =  new intent(context, detailone.class);     break;      case 1:     intent =  new intent(context, detailthree.class);     break;   default:     intent =  new intent(context, detailtthree.class);     break;     }     context.startactivity(intent);     }     });     }     };     recyclerview.setadapter(recycleradapter);     } public static class detailviewholder extends recyclerview.viewholder  { view mview; textview textview_title; textview textview_decription;  public detailviewholder(view itemview) {     super(itemview);     context = itemview.getcontext();     mview=itemview;     textview_title = (textview)itemview.findviewbyid(r.id.title);     textview_decription = (textview)   itemview.findviewbyid(r.id.description); } public void settitle(string title) {     textview_title.settext(title+""); } public void setdescription(string description) {     textview_decription.settext(description); }     }   } 

i tried add code inner class,but here progress dialog appears few seconds

 private class backgroundtask extends asynctask <void, void, void> {     private progressdialog dialog;      public backgroundtask(mainactivity activity) {         dialog = new progressdialog(activity);     }      @override     protected void onpreexecute() {         dialog.setmessage("doing something, please wait.");         dialog.show();     }      @override     protected void onpostexecute(void result) {         if (dialog.isshowing()) {             dialog.dismiss();         }     }      @override     protected void doinbackground(void... params) {         try {             thread.sleep(5000);         } catch (interruptedexception e) {             e.printstacktrace();         }          return null;     }  } 

i tried search not find example , explain

please me if know how ...


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -