I was wondering if there was anyway to use the timer class to assign to a textView in order to count down from 10 to 0 and display it in real time?
I've looked into it and found the Chronometer functions but what I understand is that it only counts up?
I'd like to learn how to do this, so is there any way to do it? and if so, how? I'm completely puzzled..
Android App Development for BeginnersA TextView displays text to the user and optionally allows them to edit it. A TextView is a complete text editor, however the basic class is configured to not allow editing.
if you need to countdown, there is the homonym class in the android.os Package called CountDownTimer.
Here (http://developer.android.com/reference/android/os/CountDownTimer.html)you can find the correct usage of this class. This is exactly what you need.
This class is present since API Level 1 so you can't fall into compatibility problems.
Example (from the docs)
new CountDownTimer(30000, 1000) {
public void onTick(long millisUntilFinished) {
mTextField.setText("seconds remaining: " + millisUntilFinished / 1000);
}
public void onFinish() {
mTextField.setText("done!");
}
}.start();
Try CountDownAnimation
. It does exactly what you need. The project includes a test.
If you use CountDownTimer
with ticks every 1 second, you will not get the last tick. So, I recommend that you try CountDownAnimation
which uses a Handler
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With