用到CountDownTimer这个类,非常简单,只有四个方法,
public final void cancel () //取消后,再次启动会重新开始倒计时
public abstract void onFinish ()
public abstract void onTick (long millisUntilFinished) //onTick的调用是同步的,保证这次调用不会在之前调用完成前发生
public synchronized final CountDownTimer start ()
实例
1 new CountDownTimer(60 * 1000, 1000) { 2 public void onTick(long millisUntilFinished) { 3 testView.setText("seconds remaining: " + millisUntilFinished / 1000); 4 } 5 public void onFinish() { 6 testView.setText("done!"); 7 } 8 }.start();
时间: 2024-12-29 04:00:35