嗨,我正在做倒计时计时器,我想在暂停后恢复它。我在不同的帖子中找不到问题的答案。当我看到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);
}
}
暂无答案!
目前还没有任何答案,快来回答吧!