我已經通過鏈接http://dewful.com/?tag=basic-android-timer關於android中的計時器應用程序。它工作正常。 我需要添加暫停按鈕來停止計時器和播放按鈕以從我停止的地方再次啓動計時器。我可以完成這項任務嗎?如何在android中暫停計時器?
我的代碼:
long timervalue = 50000;
CountDownTimer Counter1 = new CountDownTimer(timervalue, 1000)
{
public void onTick(final long millisUntilFinished)
{
time.setText(formatTime(millisUntilFinished));
pause.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Counter1.cancel();
}
}
);
resume.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Counter1.start();
timervalue = Long.parseLong(output);
System.out.println("paused timer value resumed"+timervalue);
Counter1.onTick(timervalue);
}
}
);
}
public void onFinish()
{
Counter1.cancel();
}
};
public String formatTime(long millis)
{
output = "00";
seconds = millis/1000;
seconds = seconds % 60;
System.out.println("seconds here"+seconds);
String secondsD = String.valueOf(seconds);
System.out.println("secondsD here"+secondsD);
if (seconds <
10) secondsD = "0" + seconds;
System.out.println("secondsD here in if"+secondsD);
output = secondsD;
return output;
}
在當恢復按鈕被點擊的計時器再次從50秒開始,我不希望像上面的代碼。它應該從我暫停的那一刻開始。請幫我對此...我爲這個苦苦掙扎,因爲1周......
將是幫助真的很感謝..........
查看下面的鏈接...它會幫助你希望。 http://stackoverflow.com/questions/2098642/pausing-stopping-and-starting-resuming-java-timertask-continuously – 2012-03-09 07:28:56
嗨謝謝你的鏈接....我已經通過它..可以你請告訴我如何在我的代碼中應用該代碼? – RaagaSudha 2012-03-09 11:23:10