Android uses CounterDownTimer achieve countdown

CountDownTimer is a countdown of the class, you can also specify a time interval periodic notifications, For chestnuts, for example, you are 100 seconds of the countdown, you can specify notification once every 20 seconds, when this will start a callback, the callback will be a time of 20 seconds , calls back 40 seconds ..., different methods and callback callback time at 200-second intervals.
Common methods:

  • cancel () Cancels countdown
  • onFinish () time is up, it will trigger a callback.
  • onTick regular intervals trigger callback
  • start () to start the countdown
CountDownTimer timer = new CountDownTimer(90 * 1000 - 1, 1000) {
    @Override
    public void onTick(long millisUntilFinished) {
        tvSendCode.setText(millisUntilFinished / 1000 + "s再次重发");
    }

    @Override
    public void onFinish() {
        tvSendCode.setText("重发短信验证码");
        tvSendCode.setTextColor(getResources().getColor(R.color.light_red));
        tvSendCode.setEnabled(true);
        tvSendCode.setClickable(true);
    }
}.start();

 

Published 49 original articles · won praise 2 · Views 8613

Guess you like

Origin blog.csdn.net/yangjunjin/article/details/100535756