Skip to content Skip to sidebar Skip to footer

Android Countdown Timer Display Milliseconds?

I want a timer to pop up when I click a button that will count down from 3 seconds. And it does that fine but i want it to also show the milliseconds so when I click the button the

Solution 1:

Other SO questions suggest CountDownTimer doesn't do sub 1-second granularity well. Look into a different class, like TimerTask.

Otherwise, the following would work.

new CountDownTimer(3000, 1) {
    publicvoidonTick(long millisUntilFinished) {
        textViewTimer.setText("" + millisUntilFinished / 1000
          + "." + millisUntilFinished % 1000);
    }

    publicvoidonFinish() {
        textViewTimer.setVisibility(View.INVISIBLE);
        textViewLevelGained.setVisibility(View.INVISIBLE);
    }
}.start();

Post a Comment for "Android Countdown Timer Display Milliseconds?"