如果我在此方法之外单击 buttonstop,如何停止倒数计时器?我正在制作有计时器的游戏,当我点击按钮提交并且如果答案确定答案是正确的,计时器将停止。
请帮帮我。我的项目需要它。
public void timer1(){
timer = (TextView)findViewById(R.id.timer);
final CountDownTimer Counter2 = new CountDownTimer(120000 , 1000) {
public void onTick(long millisUntilFinished) {
timer.setText( formatTime(millisUntilFinished));
}
public void onFinish() {
timer.setText("GAME OVER");
}
};
Context mcontext=this;
final AlertDialog.Builder alert = new AlertDialog.Builder(
mcontext);
alert.setTitle("LEVEL 1");
alert.setPositiveButton("Start",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
dialog.cancel();
Counter2.start();
question();
}
});
alert.show();
}
public void timer2(){
timer = (TextView)findViewById(R.id.timer);
final CountDownTimer Counter1 = new CountDownTimer(120000 , 1000) {
public void onTick(long millisUntilFinished) {
timer.setText( formatTime(millisUntilFinished));
}
public void onFinish() {
timer.setText("GAME OVER");
}
};
Context mcontext=this;
final AlertDialog.Builder alert = new AlertDialog.Builder(
mcontext);
alert.setTitle("CORRECT");
alert.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
dialog.cancel();
Counter1.start();
question();
}
});
alert.show();
}
}