问题描述
该CountDownTimer默认构造函数的值millisInFuture和countDownInterval。
如果用户停止计时器,改变了设置不同的长度millisInFuture,我将如何去改变millisInFuture值,而无需创建一个新的CountDownTimer对象?
The CountDownTimer default Constructor takes the values millisInFuture and countDownInterval.If the user stops the timer, changes his settings to a different millisInFuture length, how would I go about changing the millisInFuture value without creating a new CountDownTimer object?
我试过使得覆盖CountDownTimer类getMillisInFuture方法都无济于事。
我将不得不重写OnStart方法,还是什么?
I've tried making a getMillisInFuture method in the override CountDownTimer class to no avail.Would I have to override the onStart method, or what?
推荐答案
这个类不会让你本身做太多。
This class will not let you do much by itself.
您可以创建一个包含 CountDownTimer定时器
字段和方法更新(时间,打勾)
,一个类隐藏实现。你仍然需要调用 timer.cancel()
,并创建一个新的 CountDownTimer
使用新值。如果不是这样,或者使用从头开始创建您的倒数计时器一个处理程序
和 postDelayed(...)
You can create a class that contains a CountDownTimer timer
field and a method update(time, tick)
that hides the implementation. You would still need to call timer.cancel()
and create a new CountDownTimer
with the new values. Either that, or create your countdown timer from scratch using a Handler
and postDelayed(...)
在拿我的回答一下第二个方法的一个例子here
Take a look at an example of the second approach in my answer here
这篇关于在CountDownTimer的时候可以更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!