Pause and resume cirlce progress bar in android -


how can pause , resume circle progress bar in android ?

public void run(){     new thread(new runnable() {         @override         public void run() {             while (pstatus<100){                 pstatus += 1;                 mhandler.post(new runnable() {                     @override                     public void run() {                         mprogressbar.setprogress(pstatus);                     }                 });                 try {                     thread.sleep(200);                 }catch (interruptedexception e){                     e.printstacktrace();                 }             }         }     }).start(); } 

i need examples of circle progress(can pause , resume). please me. thanks.

i developed demo application source code follows:

public class mainactivity extends actionbaractivity {  progressbar mprogressbar; private int pstatus = 0; boolean resumed = true; private textview textview; button button1; private handler mhandler = new handler();  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);     mprogressbar = (progressbar) findviewbyid(r.id.progressbar1);     textview = (textview) findviewbyid(r.id.textview1);     button1 = (button) findviewbyid(r.id.button1);     button1.setonclicklistener(new onclicklistener() {          @override         public void onclick(view v) {             // todo auto-generated method stub             if (resumed) {                 resumed = false;             } else {                 resumed = true;             }         }     });      run();  }  public void run() {     new thread(new runnable() {         @override         public void run() {             while (pstatus < 100) {                 if (resumed) {                     pstatus += 1;                 }                 mhandler.post(new runnable() {                     @override                     public void run() {                         mprogressbar.setprogress(pstatus);                     }                 });                 try {                     thread.sleep(200);                 } catch (interruptedexception e) {                     e.printstacktrace();                 }             }         }     }).start(); }  @override public boolean oncreateoptionsmenu(menu menu) {     // inflate menu; adds items action bar if present.     getmenuinflater().inflate(r.menu.main, menu);     return true; }  @override public boolean onoptionsitemselected(menuitem item) {     // handle action bar item clicks here. action bar     // automatically handle clicks on home/up button, long     // specify parent activity in androidmanifest.xml.     int id = item.getitemid();     if (id == r.id.action_settings) {         return true;     }     return super.onoptionsitemselected(item); } } 

the actvity_main.xml file follows:

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".mainactivity" >  <progressbar     android:id="@+id/progressbar1"     style="?android:attr/progressbarstylehorizontal"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignparentleft="true"     android:layout_alignparenttop="true"     android:layout_marginleft="23dp"     android:layout_margintop="20dp"     android:indeterminate="false"     android:max="100"     android:minheight="50dp"     android:minwidth="200dp"     android:progress="1" />  <textview     android:id="@+id/textview1"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignleft="@+id/progressbar1"     android:layout_below="@+id/progressbar1" />  <button     android:id="@+id/button1"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignleft="@+id/textview1"     android:layout_below="@+id/textview1"     android:layout_margintop="52dp"     android:text="paused" />   </relativelayout> 

i able pause , resume progress bar can please try code.


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -