android - CountDownTimer strange behaviour -
hello , in advance!,
i've got countdowntimer want make pause while show increasing count 1 given number, interval. thing that, code below, counter 29 28 , don't know why.
can me?.
public void countdown(view v) { int finishnumber = 30; final countdowntimer countdown = new countdowntimer(finishnumber * 100, 100) { int numbertoshow = 1; public void ontick(long millisuntilfinished) { copyrighttv.settext(string.valueof(numbertoshow++)); } public void onfinish() { copyrighttv.settext(string.valueof(numbertoshow)); this.cancel(); } } .start(); }
it's not such strange behaviour - take consideration first ontick(long millisuntilfinished) invoked after 100ms (that interval you've set), , not when start countdowntimer.
secondly countdowntimer not 100% precise timer, can expect "strange behaviour".
edit
if accuracy not extremely important, try increasing countdowntimer few hundreds ms, this:
public void countdown(final textview v) { final int finishnumber = 30; final countdowntimer countdown = new countdowntimer((finishnumber + 4) * 100, 100) { int numbertoshow = 1; public void ontick(long millisuntilfinished) { if (numbertoshow < finishnumber) v.settext(string.valueof(numbertoshow++)); } public void onfinish() { if (numbertoshow < finishnumber) v.settext(string.valueof(numbertoshow)); } } .start(); }
Comments
Post a Comment