如何在暂停后恢复计时器而不使用公共void

t1qtbnec  于 2021-07-06  发布在  Java
关注(0)|答案(0)|浏览(187)

嗨,我正在做倒计时计时器,我想在暂停后恢复它。我在不同的帖子中找不到问题的答案。当我看到9:10时单击“暂停”,然后单击“重置时开始我的倒计时”,但我想从9:10开始继续倒计时时,我的代码看起来

mTextViewCountDown = findViewById(R.id.text_view_countdown);
    mButtonStartPause = findViewById(R.id.button_start_pause);
    mButtonStartPause.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mTimerRunning) {
                pauseTimer();
            } else {
                startTimer();
            }
        }
    });
    mCountDownTimer=new CountDownTimer(mTimeLeftInMillis,1000) {
        @Override
        public void onTick(long millisUntilFinished) {
            mTimeLeftInMillis=millisUntilFinished;
            updateCountDownText();
        }
       @Override
        public void onFinish() {
        }
    };
}
private void startTimer() {
    mTimerRunning = false;
    mButtonStartPause.setText("Start");
    mTimerRunning = true;
    mButtonStartPause.setText("pause");
    mCountDownTimer.start();
       }
private void pauseTimer() {
    mCountDownTimer.cancel();
    mTimerRunning = false;
    mButtonStartPause.setText("Start");
}
private void updateCountDownText() {
    int minutes = (int) (mTimeLeftInMillis / 1000) / 60;
    int seconds = (int) (mTimeLeftInMillis / 1000) % 60;
    String timeLeftFormatted = String.format(Locale.getDefault(), "%02d:%02d", minutes, seconds);
    mTextViewCountDown.setText(timeLeftFormatted);
}

}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题