如何扩展 CountDownTimer 添加暂停和恢复方法?
我尝试扩展 ConuntDownTimer 以这种方式添加暂停和恢复方法:
public class CountDown extends CountDownTimer {
private long resume;
private long millisInFuture;
private long countDownInterval;
public CountDown(long millisInFuture, long countDownInterval) {
super(millisInFuture,countDownInterval);
resume = millisInFuture;
this.millisInFuture = millisInFuture;
this.countDownInterval = countDownInterval;
}
public void play() {
// start
if( millisInFuture == resume ) {
super.start();
// restart
} else {
CountDown cd = new CountDown(resume, countDownInterval);
cd.play();
}
}
@Override
public void onTick(long millisUntilFinished) {
resume = millisUntilFinished;
// other code
}
}
问题是播放方法中的“重新启动”,因为通过这种方式,我创建了另一个显示错误秒数的 CountDown 实例,因为几乎有两个事件“打勾”。我能解决这个问题吗? (我希望我的英语能被理解)
I trying to extend ConuntDownTimer to add the methods pause and resume in this way:
public class CountDown extends CountDownTimer {
private long resume;
private long millisInFuture;
private long countDownInterval;
public CountDown(long millisInFuture, long countDownInterval) {
super(millisInFuture,countDownInterval);
resume = millisInFuture;
this.millisInFuture = millisInFuture;
this.countDownInterval = countDownInterval;
}
public void play() {
// start
if( millisInFuture == resume ) {
super.start();
// restart
} else {
CountDown cd = new CountDown(resume, countDownInterval);
cd.play();
}
}
@Override
public void onTick(long millisUntilFinished) {
resume = millisUntilFinished;
// other code
}
}
The problem is "restart" in the play method because, in this way, I created another istance of CountDown that display the wrong seconds because there are almost two event "onTick". Could I solve this problem? (I hope my English was understandable)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我看不出有什么方法可以通过扩展课程来实现您想要的目的。最好自己编写。 这是它的来源。
I don't see any way to do what you want by extending the class. You'll be best served writing your own. Here's the source for it.