java - ProgressDialog in Android - Indicator shows full even for 30% -


i'm trying create progress dialog shown below in code. problem when hit cancel, , click on progress bar(edit:display progress bar button) again, doesn't work expected. indicator moves faster, , times quits without completing.

this code call onclick3 when click 'click display...' button on screen shot.

progressdialog progressdialogadvanced;  public void onclick3(view v ){     showdialog(1);     progressdialogadvanced.setprogress(0);     t = new thread(new runnable() {         @override         public void run() {             for(int = 1; <=10; i++){                 try{                     thread.sleep(500);                     progressdialogadvanced.incrementprogressby((int)10);                 }catch(interruptedexception e ){                     e.printstacktrace();                 }             }             progressdialogadvanced.dismiss();         }     });     t.start(); } 

this code create progressbar:

protected dialog oncreatedialog(int id) { switch (id) {  case 1:         progressdialogadvanced = new progressdialog(this);         progressdialogadvanced.seticon(r.drawable.ic_launcher);         progressdialogadvanced.settitle("downloading...");         progressdialogadvanced.setprogressstyle(progressdialog.style_horizontal);         progressdialogadvanced.setbutton(dialoginterface.button_positive,"ok",                 new dialoginterface.onclicklistener() {                     @override                     public void onclick(dialoginterface dialoginterface, int i) {                         //to change body of implemented methods use file | settings | file templates.                         //progressdialogadvanced.setprogress(0);                             toast.maketext(getbasecontext(),"okclicked",toast.length_short).show();                         }                     });         progressdialogadvanced.setbutton(dialoginterface.button_negative,"cancel",                     new dialoginterface.onclicklistener() {                         @override                         public void onclick(dialoginterface dialoginterface, int i) {                             progressdialogadvanced.dismiss();                             toast.maketext(getbasecontext(),"cancelled",toast.length_short).show();                         }                     });         return progressdialogadvanced;   } } 

indicator showing 100% right 0 100

edit:

used cancel() instead of dismiss(). used handler shown below still doesn't fix anything. have wait till thread gets destroyed.

for(int = 1; <=10; i++){     try{         thread.sleep(500);                           }catch(interruptedexception e ){         e.printstacktrace(); }     progressbarhandler.post(new runnable() {        public void run() {            progressdialogadvanced.incrementprogressby(10);    }     }); } progressdialogadvanced.cancel(); 

you need add maximum size of progress like:

progressbar.setmax(100); 

see example: http://www.mkyong.com/android/android-progress-bar-example/


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -