我希望CountDownTimer完成后显示AlertDialog,但是尝试执行时出现错误。有没有人有解决方案或更好的方法呢?
{
new CountDownTimer(60000, 1000) {
public void onTick(long millisUntilFinished) {
mTextField.setText(":" + millisUntilFinished / 1000);
}
public void onFinish() {
mTextField.setText("GAME OVER");
mTextField.setTextSize(50);
AlertDialog.Builder ADB = new AlertDialog.Builder(getApplicationContext());
ADB.setTitle("GAME OVER")
.setMessage(R.string.app_name)
.setNeutralButton("PRESS BACK AND START GAME TO PLAY AGAIN", null)
.show();
}
}.start();
}
最佳答案
实际上您的代码完美,我可以运行但可以替换
AlertDialog.Builder ADB = new AlertDialog.Builder(getApplicationContext());
通过
用您的活动名称替换游戏
AlertDialog.Builder ADB = new AlertDialog.Builder(Game.this);
关于android - Android CountDownTimer和AlertDialog,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9696646/