英文:
After set minute I see more than I set (countdownt timer)
问题
// 倒计时计时器 {
mCountDownTimer = new CountDownTimer(millisInput, 1000) {
@Override
public void onTick(long millisUntilFinished) {
mTimeLeftInMillis = millisUntilFinished;
updateCountDownText();
tv4.setText((round_count[0] + 1) + "/" + finalNum_rounds);
}
@Override
public void onFinish() {
round_count[0]++;
if (round_count[0] < finalNum_rounds) {
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
start();
}
}, przerwasinput);
}
MediaPlayer ring = MediaPlayer.create(Main6Activity.this, R.raw.ring1);
ring.start();
tv3.setText("Przerwa");
if (!tv1.equals("00:00")) {
tv1.setText("Koniec");
}
}
}
private void updateCountDownText() {
int hours = (int) (mTimeLeftInMillis / 1000) / 3600;
int minutes = (int) ((mTimeLeftInMillis / 1000) % 3600) / 60;
int seconds = (int) (mTimeLeftInMillis / 1000) % 60;
String timeLeftFormatted;
timeLeftFormatted = String.format(Locale.getDefault(),
"%02d:%02d", minutes, seconds);
tv1.setText(timeLeftFormatted);
}
英文:
Hi I am making countdown timer. And when I put value of minutes less than one minute everything works correctly. But when I put value for example 1:05 min and click start I see counting down from 1:44. And this problem always appears when I put value bigger than 1 minute
//rundowy czasomierz {
mCountDownTimer = new CountDownTimer(millisInput, 1000) {
@Override
public void onTick(long millisUntilFinished) {
mTimeLeftInMillis = millisUntilFinished;
updateCountDownText();
tv4.setText((round_count[0]+1)+"/"+finalNum_rounds);
}
@Override
public void onFinish() {
round_count[0]++;
if (round_count[0]<finalNum_rounds){
Handler handler=new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
start();
}
}, przerwasinput);
}
MediaPlayer ring = MediaPlayer.create(Main6Activity.this, R.raw.ring1);
ring.start();
tv3.setText("Przerwa");
if (!tv1.equals("00:00")) {
tv1.setText("Koniec");
}
private void updateCountDownText(){
int hours = (int) (mTimeLeftInMillis / 1000) / 3600;
int minutes = (int) ((mTimeLeftInMillis / 1000) % 3600) / 60;
int seconds = (int) (mTimeLeftInMillis / 1000) % 60;
String timeLeftFormatted;
timeLeftFormatted = String.format(Locale.getDefault(),
"%02d:%02d", minutes, seconds);
tv1.setText(timeLeftFormatted);
}
答案1
得分: 2
我的最佳猜测是您的程序将1:05的输入解释为105秒。这相当于1分45秒,因此您的计时器会从1:45开始倒计时。
我在您的代码中没有看到处理输入的部分,所以我不确定究竟是什么导致了这个问题。
英文:
My best guess is that your program interprets an input of 1:05 as 105 seconds. This is equal to 1 minute and 45 seconds, so your timer would begin counting down from 1:45.
I don't see where in your code you process input, so I don't know exactly what is causing this.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论