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

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

jsf - "PropertyNotWritableException: Illegal Syntax for Set Operation" error when setting value in bean -

laravel - Undefined property: Illuminate\Pagination\LengthAwarePaginator::$id (View: F:\project\resources\views\admin\carousels\index.blade.php) -