倒计时器循环与动作

时间:2015-12-18 11:07:51

标签: android countdowntimer

我想将倒数计时器设置为30秒。 30秒后,我希望它做(无论如何),然后循环并再次开始30秒倒计时。

2 个答案:

答案 0 :(得分:1)

new CountDownTimer(30000, 1000)
    {

        public void onTick(long millisUntilFinished)
        {
            tv_timer.setText("seconds remaining: " + millisUntilFinished / 1000);
        }

        public void onFinish()
        {
            //do your stuff and at end of that stuff again call CountDownTimer method
        }
    }.start();

答案 1 :(得分:0)

你可以试试这个。

private final Handler mHandler = new Handler();
private final int delay = 30 * 1000; //30 secs

private void startCountDown(){
   mHandler.postDelayed(task, delay); 
}

private Runnable task = new Runnable() {
    @Override
    public void run() {

        //do something...

        if (true) { //condition to continue...
            mHandler.postDelayed(this, delay);
        }
    }
};