java - ProgressDialog appears too late -
following code:
public void onclick(view view) { dialog=new progressdialog(view.getcontext()); dialog.setcancelable(true); dialog.setmessage("initializing please wait"); dialog.settitle("loading"); dialog.setprogressstyle(progressdialog.style_spinner); dialog.setprogress(0); dialog.setmax(100); dialog.show(); progressstatus=0; new thread(new runnable() { @override public void run() { // todo auto-generated method stub while(progressstatus<10) { progressstatus=performtask(); } /*dismiss progress bar*/ myhandler.post(new runnable() { @override public void run() { // todo auto-generated method stub dialog.dismiss();//dismiss dialog toast.maketext(getbasecontext(),msg,toast.length_short).show(); progressstatus=0; myprogress=0; } }); } /* task*/ private int performtask() { try { //---simulate doing work--- thread.sleep(1000); } catch (interruptedexception e) { e.printstacktrace(); } return ++myprogress; } }).start(); }
whenever click button, progressdialog appears after 5seconds. want progressdialog show after click button..its emergency please can please ?? in advance.
do following -
class removeassignedvehicle extends asynctask<string, string, string> { /** * before starting background thread show progress dialog * */ @override protected void onpreexecute() { super.onpreexecute(); pdialog = new progressdialog(getactivity()); pdialog.setmessage("initializing please wait"); pdialog.settitle("loading"); pdialog.setprogressstyle(progressdialog.style_spinner); pdialog.setindeterminate(false); pdialog.setcancelable(true); progressstatus=0; pdialog.show(); } protected string doinbackground(string... args) { // todo auto-generated method stub while(progressstatus<10) { progressstatus=performtask(); } return ""; } protected void onpostexecute(string result) { pdialog.dismiss(); toast.maketext(getbasecontext(),msg, toast.length_short).show(); progressstatus=0; myprogress=0; }
Comments
Post a Comment