我想创建一个活动时启动一个计时器,并能够从零重置计时器,如果按下相同的按钮,但每次按下启动设置时间间隔的按钮时,它似乎都会创建一个新的时间间隔而不是重置已经创建的那个。有人可以帮忙吗?这里是我的代码如何在计时器完成时重置计时器值?
timer = (TextView) findViewById(R.id.timer_value);
Count = new CountDownTimer(time, 1000) {
public void onTick(long millisUntilFinished) {
timer.setText("Time Left: " + millisUntilFinished/1000);
}
public void onFinish() {
timer.setText("OUT OF TIME!");
if (time < 10000) {
time = 10000;
}
AlertDialog.Builder builder = new AlertDialog.Builder(
TicTacToe.this);
builder.setMessage("You are Out of Time").setPositiveButton(
"Replay", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// reset the game environment.
Count.onFinish();
// Count.cancel();
Count.start();
new_game(player_name_1);
}
});
AlertDialog alert = builder.create();
alert.show();
}
}.start();
但我有一个指定的时间为countDownTimer我怎么能实现这一点,并作为我的问题如何停止和重置计时器完成之间的计时器值和重置计时器的值。你现在可以帮我@alp –