开发者

Issue with the view when the Timer completes

I am using the following code:

public class CountDown extends CountDownTimer {

        public CountDown(long millisInFuture) {
            super(millisInFuture, 1000); 
        }

        public void onFinish() {

        }

        public void onTick(long millisUntilFinished) {

            Integer milisec = new Integer(new Double(millisUntilFinished)
                    .intValue());
            Integer cd_secs = milisec / 1000;
            Integer hours = cd_secs / 3600;
            Integer minutes = (cd_secs % 3600) / 60;
            Integer seconds = (cd_secs % 3600) % 60;
            timerText.setText(String.format("%02d", hours) + ":"
                    + String.format("%02d", minutes) + ":"
                    + String.format("%02d", seconds));
            long timeLeft = millisUntilFinished / 1000;
        }
    }

I am displaying multiple timers on the same screen.

The problem I am facing is that , when the timers completes its duration , the timer is displayed as "00:00:01"

Since multiple timers(consider 3 timers) are running with different durations , I can't hard code on the onFinish() , since on hardcoding I am getting error since other timers are still running when the one of the timer has completed.

public void onFinish() {
            secText.setText("00");
}

Kindly provide your inputs.

Is there any problem with the source code, why its not changing to "00:00:00" & stopping to "00:00:01" when the timer has completed?

Thanks in advance.

War开发者_如何学Cm Regards,

CB


Why are you using Integer and Double? These are autoboxed values and as such are slower. Also why are you using

Integer milisec = new Integer(new Double(millisUntilFinished).intValue());

when

int milisec = (int) millisUntilFinished;

should do the same thing. Also

int cd_secs = milisec / 1000;
int hours = cd_secs / 3600;
int minutes = (cd_secs % 3600) / 60;
int seconds = (cd_secs % 3600) % 60;

Should do the same thing

EDIT

The problem is most likely you're setting the interval too high in your call to the parent constructor. try super(millisInFuture, 100) Should work more reliably.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜