在设定的分钟之后,我看到的东西比我设定的要多(倒计时计时器)

huangapple go评论78阅读模式
英文:

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)+&quot;/&quot;+finalNum_rounds);
}
@Override
public void onFinish() {
round_count[0]++;
if (round_count[0]&lt;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(&quot;Przerwa&quot;);
if (!tv1.equals(&quot;00:00&quot;)) {
tv1.setText(&quot;Koniec&quot;);
}
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(),
&quot;%02d:%02d&quot;, 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.

huangapple
  • 本文由 发表于 2020年9月3日 23:24:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/63726802.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定