【发布时间】:2014-05-12 06:04:19
【问题描述】:
我试图在创建活动时启动一个计时器,如果按下相同的按钮,我可以将计时器从零重置,但每次我按下启动设置间隔的按钮时,它似乎正在创建一个新的间隔和不重置已经创建的那个。有人可以帮忙吗?这是我的代码
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();
【问题讨论】:
标签: java android timer counter countdown