Add seconds to a countdown - Android

Asked

Viewed 415 times

1

I wish that when a button was clicked, 10 seconds would be added to my timer, but I couldn’t find a way to add value to Countdowntimer, here’s my code.

private void contagemRegressiva(){
    new CountDownTimer(31000, 1000) {

        public void onTick(long millisUntilFinished) {
            tv_tempo.setText("Tempo restante: " + millisUntilFinished / 1000);
        }

        public void onFinish() {
            tv_tempo.setText("Tempo esgotado");
        }
    }.start();
  • 1

    Countdowntimer does not have this feature. See this reply where I used/created a class similar to Countdowntimer with this possibility.

  • Very interesting your answer, but is there a simpler way to solve this problem?

  • 1

    I don’t know if it’s simpler but there is. I can’t now, but I’ll put an answer later.

  • Okay, I’ll wait, thank you very much.

  • What I had thought was to cancel the current Countdowntimer and create another one with the remaining time plus 10 seconds. I will not answer because when thinking about the implementation I found that it is very "ugly". Note that the answer I mentioned does not need, for this case, to use the Countdownbehavior class. The use of the Countdown class is identical to that of Countdowntimer. The difference is that instead of implementing the abstract methods you have to implement a Countdownlistener.

  • Managed to solve?

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.