如何关闭一个Android alertdialog [英] How do I close an Android alertdialog
问题描述
我正在开发一个测验,我需要的用户,然后再继续回答所有的问题。当用户没有回答所有的问题,我展示了一个简单alertdialog通知他或她。问题是,无论我做什么,我不能让alertdialog关闭。为什么不dialog.cancel工作'这是code:?
AlertDialog.Builder广告=新AlertDialog.Builder(本);
ad.setTitle(未答复的问题);
ad.setMessage(你还没有回答所有的问题。);
ad.setPositiveButton(OK,新DialogInterface.OnClickListener(){
公共无效的onClick(DialogInterface对话框,INT ID){
dialog.cancel();
}
});
ad.show();
在 AlertDialog.Builder
本身并不包含辞退()
或取消()
方法。
这是一个方便的类来帮助你创建一个对话框,至极是否有获得这些方法。
下面是一个例子:
AlertDialog.Builder建设者=新AlertDialog.Builder(本);
AlertDialog警报= builder.create();
alert.show();
您可以再调用 alert.cancel()
方法警觉(而不是制造商)
I am developing a quiz and I need the user to answer all the questions before proceeding. When the user has not answered all the questions I display a simple alertdialog informing him or her. The problem is whatever I do I can't get the alertdialog to close. Why isn't dialog.cancel working?`This is the code:
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();
The AlertDialog.Builder
itself does not contain a dismiss()
or cancel()
method.
It is a convenience class to help you create a Dialog, wich DOES have access to those methods.
Here is an example:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
AlertDialog alert = builder.create();
alert.show();
you can then call the alert.cancel()
method on the alert (not the builder)
这篇关于如何关闭一个Android alertdialog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!