I would like to create a countdown timer that starts at 10 but only takes 5 seconds to count down to 0.
I have this code below from Google Source Code that counts down from 10:
new CountDownTimer(10000, 1000) {
public void onTick(long millisUntilFinished) {
timerText.setText("seconds remaining: " + millisUntilFinished / 1000);
}
public void onFinish() {
timerText.setText("done!");
}
}.start();
You should actually try doing it yourself first, but:
The
CountDownTimer
has two parameters in its constructor, one for the length of the timer as a whole (calledmillisInFuture
, the first parameter), and one for how often theonTick
function is called (which iscountDownInterval
). Both of these parameters are of thelong
variable type.Please see CountDownTimer in the Android API.