CountDownTimer is an abstract class available in android. This class contains two abstract method i.e. onTick(long) and onFinish().
onTick(long millisUntilFinished): Callback fired on regular interval.
onFinish() : Callback fired when the time is up.
This class schedule a countdown until a time in the future, with regular notifications on intervals along the way.
An Example of CountDownTimer class showing a 30 second countdown in a text field:-
Declare a two long constant:-
private final long TOTAL_DURATION = 30000, COUNT_INTERVAL = 1000;
Now in the onCreate() method:-
new CountDownTimer(TOTAL_DURATION, COUNT_INTERVAL) {
public void onTick(long millisUntilFinished) {
timerTextView.setText("seconds remaining: " + millisUntilFinished / 1000);
}
public void onFinish() {
timerTextView.setText("done!");
}
}.start();
Your 30 seconds CountDown is ready.
1 Comment(s)