开发者

Starting and handling multiple CountDownTimers in Android

开发者 https://www.devze.com 2023-02-06 20:34 出处:网络
开发者_运维知识库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?

开发者_运维知识库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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号