-1
使用了幾個教程,我設法在countdowntimer下面創建 - 這讓我爲自己感到驕傲:) 現在我希望這個計時器也能夠啓動窗體而不是從頭開始? 所有想法//鏈接/教程歡迎。嗨,如何從變量啓動android計時器
預先感謝您。
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");
}
}