Reputation: 2318
I am developing a Question answer game. So a Timer is a must.
I want the timer for 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 advance
Upvotes: 2
Views: 374
Reputation: 67286
Well 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();
Upvotes: 3