alcatrazbr
3/28/2017 - 11:04 AM

countdowntimer - timer de contagem regressiva

countdowntimer - timer de contagem regressiva


    private void startCountdown() {
        final SimpleDateFormat df = new SimpleDateFormat("mm:ss");
        buttonSendCode.setEnabled(false);

        if(countDownTimer != null) countDownTimer.cancel();

        countDownTimer = new CountDownTimer(MILLISECONDS_TO_RESEND, 1000) {
            public void onTick(long millisUntilFinished) {
                buttonSendCode.setText(df.format(new Date(millisUntilFinished)));
            }

            public void onFinish() {
                buttonSendCode.setText(getString(R.string.resend_code));
                buttonSendCode.setEnabled(true);
            }
        }.start();
    }