Most visited

Recently visited

Added in API level 1

CountDownTimer

public abstract class CountDownTimer
extends Object

java.lang.Object
   ↳ android.os.CountDownTimer


安排倒计时,直到将来的某个时间,定期通知时间间隔。 在文本字段中显示30秒倒数的示例:

 new CountDownTimer(30000, 1000) {

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

     public void onFinish() {
         mTextField.setText("done!");
     }
  }.start();
 
The calls to onTick(long) are synchronized to this object so that one call to onTick(long) won't ever occur before the previous callback is complete. This is only relevant when the implementation of onTick(long) takes an amount of time to execute that is significant compared to the countdown interval.

Summary

Public constructors

CountDownTimer(long millisInFuture, long countDownInterval)

Public methods

final void cancel()

取消倒计时。

abstract void onFinish()

当时间到了时,回调被触发。

abstract void onTick(long millisUntilFinished)

定期触发回调。

final CountDownTimer start()

开始倒计时。

Inherited methods

From class java.lang.Object

Public constructors

CountDownTimer

Added in API level 1
CountDownTimer (long millisInFuture, 
                long countDownInterval)

Parameters
millisInFuture long: The number of millis in the future from the call to start() until the countdown is done and onFinish() is called.
countDownInterval long: The interval along the way to receive onTick(long) callbacks.

Public methods

cancel

Added in API level 1
void cancel ()

取消倒计时。

onFinish

Added in API level 1
void onFinish ()

当时间到了时,回调被触发。

onTick

Added in API level 1
void onTick (long millisUntilFinished)

定期触发回调。

Parameters
millisUntilFinished long: The amount of time until finished.

start

Added in API level 1
CountDownTimer start ()

开始倒计时。

Returns
CountDownTimer

Hooray!