android countdown timer continues to run in background
I want to make a 30 second countdown to run in my activity and continue to run until it hits 0. Is there any method?
Basically I want it to run and up开发者_运维技巧date its value in a textview.
You can do it this way
new CountdownTimer(30000, 1000) {
public void onTick(long millisUntilFinished) {
mTextField.setText("seconds remaining: " + millisUntilFinished / 1000);
}
public void onFinish() {
mTextField.setText("done!");
}
}.start()
;
Check this: http://coderzheaven.com/2011/08/simple-countdown-timer-in-android/ for a complete example using CountDownTimer.
精彩评论