Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I add numbers into a countdown timer so it counts a different number each time it finishes?
    primarykey
    data
    text
    <p>Basically I have made a countdown timer using android, the CountDownTimer class, a TextView and a button. It all works fine.</p> <p>My problem is that I want my countdown timer to change its time each time one of the countdowns has finished.</p> <p>For example: The countdown timer starts of by counting down from 5 minutes, now once that countdown has finished I want the countdown to automatically start again but from a different time say 1 minute and it continues like that.</p> <p>So it should go 5 minutes then 1 minute then say 2 minutes and then 30 seconds then stop. Here is how the time is defined already:</p> <pre><code> counter = new CountDownTimer(300000, 1000) { public void onTick(long millisUntilFinished) { tv.setText(formatTime(millisUntilFinished)); } public void onFinish(){ System.out.println("Finished"); } }; </code></pre> <p>The 300000 is the milliseconds it counts down from so therefore 5 minutes and the 1000 is the countdown interval, so 1 second.</p> <p>So now the question remains: are there any ways to make it start counting down from 5 minutes then automatically start a countdown from a minute then 2 minutes then 30 seconds as an example?</p> <p>I have tried using an array so here is the code I used but the for loop was too fast.</p> <p>The array: </p> <pre><code> int[] week1day1 = {10000, 20000, 30000}; </code></pre> <p>The loop:</p> <pre><code> for (int arrayValue = -1; arrayValue &lt; week1day1.length; arrayValue++) { maxTime = week1day1[arrayValue]; counter.start(); tv.setText("Pause"); System.out.println("Array Value"); } </code></pre> <p>In the logcat "Array Value" shows up twice and in the space of about 10 milliseconds. So I think the loop is not waiting for the maxTime to count down and therefore loops straight to the end of the array.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload