android - Enabling and update progressbar from a thread -


progressbar not show when try access thread nor update progress. prefer have progress spinner displayed until network activity complete, , network activity post text data server.this code have far, appreciated thanks,

 thread th = new thread(){         public void run() {                       try {                         sleep(5000);                           while(cnt < 5000){                              activty.this.runonuithread(new runnable(){                                  public void run()                                  {                                      progressbar pd = (progressbar)findviewbyid(r.id.progressbar1);                                     pd.setvisibility(0);                                     pd.setmax(100);                                       pd.setprogress(cnt);                                     cnt += 100;                                  }                              });                          }                      } catch (interruptedexception e) {                             // todo auto-generated catch block                             e.printstacktrace();                         }         }          int cnt = 100;     };     th.start();     ` 

this case want use asynctask, processes data in separate thread , contains methods publishprogress , onprogressupdate update ui on ui thread.

the processes , threads guide has example of how implement asynctask well.


Comments