结束轮班时设置暂停时出现问题。当用户单击按钮时,它将开始倒计时,完成的文本将根据需要返回其值。但是我要在倒数计时器(定时器)完成后启动另一个timer2。现在开始同时计数。每个计时器在屏幕上都有自己的textView。
这是代码:
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
long roundtime= Long.parseLong(String.valueOf(msg1))*1000; //User set Time for Round
long pause= Long.parseLong(String.valueOf(msg2))*1000; //User set Time for Pause
Counting timer = new Counting(roundtime, 1000); // class CountdownTimer
Counting2 timer2 = new Counting2(pause, 1000); // class CountdownTimer
timer.start(); // I want to start with this timer first
timer2.start(); // And when timer is finished start with this in own textView
}
enter image description here
最佳答案
使用CountDownTimer。从根本上讲,您需要什么。只需启动一个计时器,然后在该计时器的onFinish()
方法上启动新计时器。就像是:
CountDownTimer timer1 = new CountDownTimer(30000, 1000) {
public void onTick(long millisUntilFinished) {
//do whatever you need here, this gets called every 1000 milliseconds (the 2nd parameter
of the constructor, the first is total time in ms
}
public void onFinish() {
CountDownTimer timer2 = new CountDownTimer(5000, 1000) {
//same logic
};
timer2.start();
}
};
timer1.start();