使用了几个教程我设法创建了以下countdowntimer - 这让我为自己感到骄傲:) 现在我希望这个计时器能够从停止而不是从头开始再次启动时启动吗? 欢迎所有想法//链接/教程。
提前谢谢你。
setTime(0);
}
private void setTime(int seconds) {
// TODO Auto-generated method stub
Time = seconds;
int minutes = seconds / 60;
seconds = seconds % 60;
tvCzas.setText(String.format("%02d:%02d", minutes, seconds));
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (v == bAddSec)
setTime(Time + 1);
else if (v == bTakeSec)
setTime(Time - 1);
else if (v == bAddMinute)
setTime(Time + 60);
else if (v == bTakeMinute)
setTime(Time - 60);
else if (v == bReset)
setTime(0);
else if (v == bStart)
if (mierzy)
zatrzym();
else
rozpocznij();
}
private void rozpocznij() {
// TODO Auto-generated method stub
Timer = new CountDownTimer(Time * 1000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
int millis = (int) millisUntilFinished;
int seconds = (int) millisUntilFinished / 1000;
int minutes = seconds / 60;
millis = millis % 100;
seconds = seconds % 60;
tvCzas.setText(String.format("%02d:%02d", minutes, seconds));
bStart.setText("Stop");
}
@Override
public void onFinish() {
// TODO Auto-generated method stub
mierzy = false;
setCount(Licznik + 1);
tvCzas.setText("Koniec!");
bStart.setText("Start");
}
};
Timer.start();
bStart.setText("Stop");
mierzy = true;
}
private void zatrzym() {
// TODO Auto-generated method stub
if (Timer != null)
Timer.cancel();
mierzy = false;
bStart.setText("Start");
}
}