Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid countdown not working properly, numbers keeps flickering between 2 values and timezone not working
    text
    copied!<p>I got a countdown that counts down to a specific date. Each tick (interval 1 second) updates a textbox with the days/hours/minutes left until the event. My problem is that the minutes (don't know about the days/hours yet) keeps flickering. Meaning it says 18 then 17 then 18 then 17 during the minute before going down to 16 then 17 then 16 and it continues to do like that. </p> <p>Flickering problem solved, now its just the timezone that is not working. (Flickering was solved using the code from Pshemo)</p> <p>Also the TimeZone doesn't appear to be working. It shows 2 hours to much. Have tried to change it using SimpleTimeZone but it doesn't work, still showing the +2 hours (regardless of the settings on SimpleTimeZone)</p> <p>What could be the cause?</p> <p>Countdown code:</p> <pre><code> new CountDownTimer(remaining, 1000) { TextView tv = (TextView)getActivity().findViewById(R.id.introTimeLeft); public void onTick(long millisUntilFinished) { SimpleTimeZone ts = new SimpleTimeZone(2, "Middle Europe"); Calendar cal = Calendar.getInstance(ts); cal.set(2012, 5, 28, 17, 0); long endTime = cal.getTimeInMillis(); long currentTime = System.currentTimeMillis(); long remaining = endTime - currentTime; tv.setText(getDurationBreakdown(remaining)); } ... }.start(); public String getDurationBreakdown(long millis) { if(millis &lt; 0) { throw new IllegalArgumentException("Duration must be greater than zero!"); } long days = TimeUnit.MILLISECONDS.toDays(millis); millis -= TimeUnit.DAYS.toMillis(days); long hours = TimeUnit.MILLISECONDS.toHours(millis); millis -= TimeUnit.HOURS.toMillis(hours); long minutes = (long) Math.ceil(TimeUnit.MILLISECONDS.toMinutes(millis)); StringBuilder sb = new StringBuilder(64); sb.append(days); sb.append(" Days "); sb.append(hours); sb.append(" Hours "); sb.append(minutes); sb.append(" Minutes"); return(sb.toString()); } </code></pre>
 

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