我正在开发一个类似于秒表游戏的Android应用程序。无论如何,截至目前,圆形进度条在第一次启动和停止时均能正常工作,但是此后,圆形进度条就吓坏了,我希望它可以一直运行直到时间耗尽,无论是否触摸停止按钮。同样,如果在计时器开启时按下复位按钮,则会产生巨大的随机时间。任何帮助将不胜感激。
以下是一些代码:
/**
* method to initialize the values for count down timer
*/
/**
* method to start count down timer
*/
private void startCountDownTimer() {
countDownTimer = new CountDownTimer(timeCountInMilliSeconds, 1000) {
@Override
public void onTick(long millisUntilFinished) {
timeUntilDone = (int)(millisUntilFinished/1000);
textViewTime.setText(hmsTimeFormatter(millisUntilFinished));
progressBarCircle.setProgress((int) (millisUntilFinished / 1000));
}
@Override
public void onFinish() {
textViewTime.setText(hmsTimeFormatter(timeCountInMilliSeconds));
// call to initialize the progress bar values
setProgressBarValues();
// hiding the reset icon
imageViewReset.setVisibility(View.GONE);
// changing stop icon to start icon
imageViewStartStop.setImageResource(R.drawable.icon_start);
// making edit text editable
editTextMinute.setEnabled(true);
// changing the timer status to stopped
timerStatus = TimerStatus.STOPPED;
pauseClock();
stopWatch.setText("0:00:00");
// stopCountDownTimer();
// stopCountDownTimer();
}
}.start();
if (timerStatus==TimerStatus.STOPPED) {
countDownTimer.start();
}
else{
startClock();
}
}
/**
* method to stop count down timer
*/
private void stopCountDownTimer() {
countDownTimer.cancel();
}
/**
* method to set circular progress bar values
*/
private void setProgressBarValues() {
progressBarCircle.setMax((int) timeCountInMilliSeconds / 1000);
progressBarCircle.setProgress((int) timeCountInMilliSeconds / 1000);
}
/ **
* method to reset count down timer
*/
private void reset() {
startTime = 01; timeInMilliseconds =01; timeSwapBuff = 01; updateTime=01;
stopWatch.setText("0:00:00");
progressBarCircle.setProgress(timeUntilDone);
}