倒数计时器暂停和恢复 [英] Countdown timer with pause and resume

查看:615
本文介绍了倒数计时器暂停和恢复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的倒计时定时器暂停和restart.Now我显示倒计时通过implenting ontick()和onfinish()。请帮我out.HEre是个$ C $下倒数计时器

 最后CountDownTimer计数器1 =新CountDownTimer(timervalue1,1000)

     {
 公共无效onTick(长millisUntilFinished)

  {
            的System.out.println(onTick方法!(将String.valueOf(millisUntilFinished / 1000)));长S1 = millisUntilFinished;
  }

公共无效onFinish()

{
            的System.out.println(完了!);
}

}
 

解决方案

在onTick method..save离开毫秒

 长S1 = millisUntilFinished;
 

当要暂停定时器使用。

  Counter.cancel();
 

当你想恢复建立一个新的countdowntimer左毫秒。

  timervalue = S1
  计数器=新C1的();
   counter.start();
 

<一个href="http://stackoverflow.com/questions/9630398/how-can-i-pause-the-timer-in-android/9663508#9663508">See此链接

I want to do countdown timer with pause and restart.Now i am displaying countdown timer By implenting ontick() and onfinish().please help me out.HEre is th code for countdown timer

final CountDownTimer Counter1 = new CountDownTimer(timervalue1 , 1000)

     {
 public void onTick(long millisUntilFinished)

  {
            System.out.println("onTick method!"(String.valueOf(millisUntilFinished/1000)));long s1=millisUntilFinished;
  }

public void onFinish() 

{
            System.out.println("Finished!");
}

}

解决方案

in onTick method..save the milliseconds left

   long s1=millisUntilFinished;

when you want to pause the timer use..

   Counter.cancel();

when you want to resume create a new countdowntimer with left milliseconds..

 timervalue=s1
  counter= new Counter1();
   counter.start();

See this link

这篇关于倒数计时器暂停和恢复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆