java - my timer in eclipse did not work properly -
i new eclipse , timer in eclipse did not work properly, java. code in timer:
button countdownbutton2 = (button) findviewbyid(r.id.countdown1); countdownbutton2.setonclicklistener(new view.onclicklistener() { public void onclick(view view){ countdowntimer timer2 = new countdowntimer(3000,1000){ @override public void onfinish() { mtimelabel1.settext("times baby!"); } @override public void ontick(long millisuntilfinished) { int seconds = (int) (millisuntilfinished / 1000); int minutes = seconds / 60; seconds = seconds % 60; mtimelabel1.settext("" + minutes + ":" + string.format("%02d", seconds)); } }.start(); } });
basically running wish, however, found if clicked trigger button while counting, trigger counting without stop previous counting. embarrassing, friend suggest me "switch" if button trigger again, , considering add actions same button stop restart counting. 1 more preferable?
disable trigger button while timer running.
that way save pain fiqure out how switch or adding other actions button after first click.
you try yourbutton.setenabled(false);
make disabled.
if have understood code right, should be
countdownbutton2.setenabled(false);
to enable button again, use
countdownbutton2.setenabled(true);
Comments
Post a Comment