开发者

android countdown timer continues to run in background

开发者 https://www.devze.com 2023-04-01 10:38 出处:网络
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?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消