android - Countdown timer not working properly -
i trying use timer
...when call countdowntimer.start()
i can see in debugger timeleft variable updated value=120000
want timer doesn't execute ontick
method. jumps straight onfinish
. if give timeleft
literal works.
volatile long timeleft=0; countdowntimer countdowntimer=new countdowntimer( timeleft,1000) { @override public void ontick(long timeleft) { textview timeview= (textview)findviewbyid(r.id.timer); long longtime=(timeleft / 1000); integer inttime=(int)longtime;// convert long int timeview.settext(string.valueof(inttime));} @override public void onfinish() {correctdialog("sorry,time up!!");}};} (timeleft not fixed)
here first parameter in countdowntimer()
constructor millisinfuture
. giving value 0. finish whenever start timer. give value how time want execute times 10000 or 20000 etc...
so initialize timeleft
volatile long timeleft=10000;
check documentation countdowntimer
Comments
Post a Comment