我想要检查一个条件,如果它是假的,我想要取消之前显示的AlertDialog。然而,我正面临这样的错误:
未为类型AlertDialog.Builder定义dismiss()方法
代码:
ad.show();
if (call.isInCall()== false)
{
ad.dismiss();
}问题出在哪里?
编辑:问题:
AlertDialog.Builder ad = new AlertDialog.Builder(context);
d = ad.create();
ad.setTitle("Appel en cours...");
ad.setMessage("Voulez vous répondre à cet appel?");
//ad.create();
ad.setPositiveButton("Oui",
.....
if(call.isInCall() == false && d != null && d.isShowing()){
d.dismiss();
}=>强制关闭。非常感谢你的帮助。
发布于 2011-04-27 22:17:07
您必须先使用构建器创建对话框,然后才能执行此类操作。
//Let's change this so you have a field declared in your class.
AlertDialog d;
//Somewhere, maybe in onCreate() you're using the builder to instantiate the dialog.
//insert all builder creation and methods here first... then call
d = ad.create();
//somewhere else in your code you've shown the dialog with
d.show();
//again, some where else you're checking if the dialog is displaying and dismissing it
if(call.isInCall() == false && d != null && d.isShowing()){
d.dismiss();
}当然,您必须小心使用AlertDialog上的作用域,这取决于您调用此代码的位置。这也不是真正推荐的处理对话框的方法。您应该研究一下onCreateDialog() onPrepareDialog()活动回调函数的用法:http://developer.android.com/guide/topics/ui/dialogs.html
https://stackoverflow.com/questions/5805479
复制相似问题