在CountDownTimer的时候可以更新? [英] Can the time on a CountDownTimer be updated?

查看:122
本文介绍了在CountDownTimer的时候可以更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该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(...)

在拿我的回答一下第二个方法的一个例子<一个href=\"http://stackoverflow.com/questions/5784694/count-for-45-seconds-pause-for-20-then-repeat-with-different-title/5785878#5785878\">here

Take a look at an example of the second approach in my answer here

这篇关于在CountDownTimer的时候可以更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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