Starting and handling multiple CountDownTimers in Android
开发者_运维知识库In Android, I need to start and display multiple CountDownTimers at the same time, on the same screen, one after another. How can I proceed implementing this? Will using threads help?
you can define and array or list for each timer you want to run, and define a timer that decrements them every second.
https://chat.stackoverflow.com/users/443141
has an example on how to schedule tasks every second. In the method that gets called every second, decrement the values of all arrays and update a text-label.
...
for ( int i=0; i < timers.length; i++) {
if ( timers[i] > 0 ) {
timers[i]--;
// update your textlabel
} else {
// change the text color, flash,vibrate,...
}
}
...
to reset a timer simply set a new seconds left value.
精彩评论