android - CountDownTimer's OnFinish() fires when the timer is Halfway in its countdown -
i've used countdowntimer in android project, , happens, is, onfinish() fires while countdown in half way stage.
here code :
public void shownotice(){ cdt = new countdowntimer(10000, 1000) { @override public void ontick(long millisuntilfinished) { // todo auto-generated method stub toast toast = toast.maketext(con,"game starts in :"+string.valueof(millisuntilfinished/1000), toast.length_short); toast.setgravity(gravity.center_horizontal, 0, 0); toast.show(); } @override public void onfinish() { // todo auto-generated method stub removebuttontext(); } }; cdt.start(); } removebuttontext();// method gets executed when count down isn't finished i.e toast shows '5'.
note : cdt declared private member variable inside class of type countdowntimer.
need :)
i've solved problem.
public void shownotice(){ cdt = new countdowntimer(20000, 2000) { @override public void ontick(long millisuntilfinished) { // todo auto-generated method stub toast toast = toast.maketext(con,"game starts in :"+string.valueof(millisuntilfinished/2000), toast.length_short); toast.setgravity(gravity.bottom, 0, 0); toast.show(); } @override public void onfinish() { // todo auto-generated method stub toast toast = toast.maketext(con,"game starts now!", toast.length_short); toast.setgravity(gravity.bottom, 0, 0); toast.show(); removebuttontext(); } }; cdt.start(); } the catch in getting this
cdt = new countdowntimer(20000, 2000) right.
thank :)
Comments
Post a Comment