这是我的第一个问题。我需要在我的应用程序中实现一个接一个运行的countdown timers。当第一次完成时,下一次就开始了,等等。每次运行的Init time取决于用户的输入。问题是,对于每一个运行的onTick()和onFinish()方法,我都需要在countdown timer和onFinish()方法中放置不同的代码,而且,我不知道如何在完成一个counter之后启动下一个counter。我正在考虑在当前方法的counter方法中调用next onFinish(),但是我想不出如何用6 counters来实现这一点。
这是我的倒计时课:
public class Counter extends CountDownTimer
{
public Counter(long millisInFuture, long countDownInterval)
{
super(millisInFuture, countDownInterval);
}
public void onTick(long millisUntilFinished)
{
//this code is the same for every counter
timer_view.setText(formatTime(millisUntilFinished));
//this code depends on specific counter running
output_view1.setText("My output here");
output_view2.setText("My output here");
output_view3.setText("My output here");
}
public void onFinish()
{
playSound(sound_id_1);
runMyMethod(user_input_1);
timerHasStarted = false;
}
}我在同一活动中启动我的柜台:
if(!timerHasStarted)
{
counter = new Counter(user_input1, 1000);
counter.start();
}发布于 2014-02-04 16:08:28
你从来没有
timerHasStarted敬真。这总是错误的,so...yeah,一个接一个的计时器。在调用counter.start()之前将其设置为true,它应该可以工作。
https://stackoverflow.com/questions/21555209
复制相似问题