我正在开发测验,并且需要用户在继续之前回答所有问题。当用户没有回答所有的问题时,我会显示一个简单的alertdialog通知他或她。问题是无论我做什么我都无法让alertdialog关闭。为什么不dialog.cancel工作`这是代码:如何关闭Android alertdialog
AlertDialog.Builder ad = new AlertDialog.Builder(this);
ad.setTitle("Unanswered Questions");
ad.setMessage("You have not answered all the questions.");
ad.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
ad.show();
将代码包装在代码标签中,以便问题可读。 – jacknad 2010-12-02 15:17:11
尝试解雇()? – Vjy 2010-12-02 15:17:30
应该工作。我可以建议你尝试调试每一步,看看是否调用了ad.show()。哦,还有onClick方法。 – achie 2010-12-02 15:24:14