我有一个带有倒数计时器的 AlertDialog,我有一个取消按钮设置,它取消了对话框,但计时器继续运行!有谁知道如何取消倒数计时器的倒计时?任何帮助,将不胜感激!
private void timerDialog() {
timerDialog = new AlertDialog.Builder(this).create();
timerDialog.setTitle("Timer");
timerDialog.setMessage("Seconds Remaining: "+timerNum*1000);
timerDialog.setCancelable(false);
timerDialog.setButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface aboutDialog, int id) {
timerDialog.cancel();
}
});
timerDialog.show();
new CountDownTimer(timerNum*1000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
timerDialog.setMessage("Seconds Remaining: "+ (millisUntilFinished/1000));
}
@Override
public void onFinish() {
Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate(500);
timerDialog.cancel();
}
}.start();
}