I need to display a timer with hours, minutes and seconds. Currently I use android.os.CountDownTimer(1000*60*60, 1000). I have a feeling it's not a perfect fit for my needs, because I don't need it to stop, so I resort to entering huge values as the countdown value.
Am I p开发者_如何转开发erhaps missing another method for showing time ticks, indefinitely?
In my case the example above start working only after i made changes like this:
private final Runnable mUpdateTimeTask = new Runnable() {
@Override
public void run() {
final long start = 0;
// long millis = SystemClock.uptimeMillis() ;
long millis = SystemClock.uptimeMillis() - start;
int seconds = (int) (millis / 1000);
int minutes = seconds / 60;
seconds = seconds % 60;
if (seconds < 10) {
waitingTime_Time.setText("" + minutes + ":0" + seconds);
} else {
waitingTime_Time.setText("" + minutes + ":" + seconds);
}
mHandler.postAtTime(this,
start + (((minutes * 60) + seconds + 1) * 1000));
}
};
mStartTime = System.currentTimeMillis();
- returns the value much more than mStartTime = System.currentTimeMillis();
and that's cause negative value to update.
But with setting start time to zero, timer updates every 100 millisec.
精彩评论