android - progress dialog will not show up -


i want pressing button show progress dialog , dismiss when function done. code below , although it's easy unknown reason me won't run.

final button button = (button) findviewbyid(r.id.syncbtn);     button.setonclicklistener(new view.onclicklistener() {         public void onclick(view v) {             // perform action on click             progressdialog progressdialog = new progressdialog(mainactivity.this);             progressdialog.setprogressstyle(progressdialog.style_spinner);             progressdialog.setcancelable(false);             progressdialog.settitle("please wait..");             progressdialog.setmessage("preparing download ...");             progressdialog.show();              bringdata();              progressdialog.dismiss();         }     }); 

two possibilities can think of why not working you:

  1. the method "bringdata()" executed on ui thread. ui thread doing work (executing bringdata) , won't redraw ui. afterwards dismiss dialog , seems dialog not showing.

  2. in method "bringdata()", start background thread. in scenario show dialog , dismissing directly.

since using volley, mentioned in comment, have dismiss dialog when request has finished. therefore have dismiss dialog in callback method.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -