简单使用
CountDownTimer
CountDownTimer(总的时间, 时间间隔)
private CountDownTimer countDownTimer = new CountDownTimer(10000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
// String value = String.valueOf((int) (millisUntilFinished / 1000));
// tvMain.setText(value);
tvMain.setText("倒计时还剩:" + millisUntilFinished / 1000 + "秒");
}
@Override
public void onFinish() {
tvMain.setText("finish");
}
};
调用
countDownTimer.start();
效果
写一个类继承使用
使用
CountDown countDown;
class CountDown extends CountDownTimer {
public CountDown(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
@Override
public void onFinish() {
tvMain.setText("finish");
}
@Override
public void onTick(long millisUntilFinished) {
tvMain.setText("请等待10秒(" + millisUntilFinished / 1000 + ")...");
}
}
调用
countDown = new CountDown(10000, 1000);
countDown.start();
效果
欢迎指错,一起学习