android - Can't get coundown timer to work or display in my program -


i'm newer programmer , first project i'm having bit of trouble in making proper loop 3 timers supposed run 1 after other. managed objects hold values supposed within loop reason, timer isn't displaying in text field should.

          startbtn.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             log.i("mtimer:", string.valueof(mtimer));             log.i("mreps:", string.valueof(mreps));             log.i("flexion:", string.valueof(flexiontimer));             log.i("hold:", string.valueof(holdtimer));             log.i("extension:", string.valueof(extensiontimer));              (int iter = 0; iter < mreps; iter++) {                 log.i("loop:", string.valueof(iter));                  final timer workingflexiontimer = new timer();                 workingflexiontimer.schedule(new timertask() {                     int counter = ((int) flexiontimer / 1000);                     @override                     public void run () {                         runonuithread(new runnable() {                             @override                             public void run() {                                 mphase.settext("flexion");                                 mcountdowntimer.settext("" + string.format(string.valueof(counter + 1)));                             }                         });                         if (counter-- == 0) {                             workingflexiontimer.cancel();                         }                     }                 }, 0, 1000);                   final timer workingholdtimer = new timer();                 workingholdtimer.schedule(new timertask() {                     int counter = ((int) holdtimer / 1000);                     @override                     public void run() {                         runonuithread(new runnable() {                             @override                             public void run() {                                 mphase.settext("hold!!!");                                 mcountdowntimer.settext("" + string.format(string.valueof(counter + 1)));                             }                         });                         if (counter-- == 0) {                             workingholdtimer.cancel();                         }                     }                 }, flexiontimer, 1000);                  final timer workingextensiontimer = new timer();                 workingextensiontimer.schedule(new timertask() {                     int counter = ((int) extensiontimer / 1000);                     @override                     public void run() {                         runonuithread(new runnable() {                             @override                             public void run() {                                 mphase.settext("extension");                                 mcountdowntimer.settext("" + string.format(string.valueof(counter + 1)));                             }                         });                         if (counter-- == 0) {                             workingextensiontimer.cancel();                         }                     }                 }, (flexiontimer + holdtimer), 1000);             } 

i'm kind of @ loss @ point , suggestion appreciated.

update

for timers do:

    final textview textview = (textview)findviewbyid(r.id.textview);     timer timer = new timer();     timer.schedule(new timertask() {         int counter = 10;         @override         public void run() {             runonuithread(new runnable() {                 @override                 public void run() {                     textview.settext(""+counter);                 }             });              if (counter-- == 0){                 timer.cancel();             }          }     }, 0, 1000);  timer.schedule(new timertask() {         int counter = 10;         @override         public void run() {             runonuithread(new runnable() {                 @override                 public void run() {                     textview.settext(""+counter);                 }             });              if (counter-- == 0){                 timer.cancel();             }          }     }, 10000, 1000);   timer.schedule(new timertask() {         int counter = 10;         @override         public void run() {             runonuithread(new runnable() {                 @override                 public void run() {                     textview.settext(""+counter);                 }             });              if (counter-- == 0){                 timer.cancel();             }          }     }, 20000, 1000); 

for more info check this

in link...

public void schedule(timertask task, long delay, long period)

the above code. start run() without delay.

long delay = 0;// in ms long period = 1000;// in ms 

so every 1000ms call run() , counter--. when counter = 0 cancel.

if want run, 1 after other, put delay.

update

now first run immediately, second wait 10000ms (10s) , run, finaly third wait 20000ms (20s) , run.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -