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:
the method "bringdata()" executed on ui thread. ui thread doing work (executing bringdata) , won't redraw ui. afterwards dismiss dialog , seems dialog not showing.
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
Post a Comment