Xet*_*mer 4 android countdowntimer
在android参考资料中我发现了一个关于countdowntimers的页面: CountDownTimers
它里面有这段代码:
new CountDownTimer(30000, 1000) {
public void onTick(long millisUntilFinished) {
mTextField.setText("seconds remaining: " + millisUntilFinished / 1000);
}
public void onFinish() {
mTextField.setText("done!");
}
}.start();
Run Code Online (Sandbox Code Playgroud)
我想知道它是什么,以及它是一个对象或类,以及如何将它用作不同类对象的计时器.有人可以解释我将如何把它放入我的android项目并使用它.谢谢.
公共建筑师:
CountDownTimer(long millisInFuture, long countDownInterval)
Run Code Online (Sandbox Code Playgroud)
公共方法:
final void cancel()
Cancel the countdown.
abstract void onFinish()
Callback fired when the time is up.
abstract void onTick(long millisUntilFinished)
Callback fired on regular interval.
synchronized final CountDownTimer start()
Start the countdown.
Run Code Online (Sandbox Code Playgroud)
公共建筑师:
public CountDownTimer (long millisInFuture, long countDownInterval)
Parameters
1. millisInFuture The number of millis in the future from the call to start() until the countdown is done and onFinish() is called.
2. countDownInterval The interval along the way to receive onTick(long) callbacks.
Run Code Online (Sandbox Code Playgroud)
公共方法:
public final void cancel ()
Cancel the countdown.
public abstract void onFinish ()
Callback fired when the time is up.
public abstract void onTick (long millisUntilFinished)
Callback fired on regular interval.
Parameters: millisUntilFinished The amount of time until finished.
public final synchronized CountDownTimer start ()
Start the countdown.
Run Code Online (Sandbox Code Playgroud)
教程链接:
编辑:
new CountDownTimer(30000 /*For how long should timer run*/, 1000 /*time interval after which `onTick()` should be called*/) {
public void onTick(long millisUntilFinished) {
Log.i("Countdown Timer: ","seconds remaining: " + millisUntilFinished / 1000);
}
public void onFinish() {
//Done timer time out.
myTextView.setText("Time Out.!");
}
}.start();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3547 次 |
| 最近记录: |