How to set up a timer that also checks for an event when running
I am developing a Question answer game. So a Timer is a must. I want the timer 开发者_如何学JAVAfor 30s. The timer should be running in the UI and when an onclick event like pressing a button occurs , that event should be triggered and the timer should be reset. If the timeout occurs it must display a timeout message and exit.
HELP! Thanks in advanceWell this is the best way to do that I guess a CountDownTimer
new CountDownTimer(Totalmiliseconds, interval) {
@Override
public void onTick(long intervalInMili) {
tv.setText("second remaining - "+intervalInMili/1000);
}
@Override
public void onFinish() {
tv.setText("Done!!!!!!!!!!!!");
}
}.start();
精彩评论