首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >alertdialog.dismiss()出错

alertdialog.dismiss()出错
EN

Stack Overflow用户
提问于 2011-04-27 22:10:06
回答 1查看 2.6K关注 0票数 0

我想要检查一个条件,如果它是假的,我想要取消之前显示的AlertDialog。然而,我正面临这样的错误:

未为类型AlertDialog.Builder定义dismiss()方法

代码:

代码语言:javascript
复制
ad.show();
        if (call.isInCall()== false)
        {
            ad.dismiss();
        }

问题出在哪里?

编辑:问题:

代码语言:javascript
复制
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();
        }

=>强制关闭。非常感谢你的帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-04-27 22:17:07

您必须先使用构建器创建对话框,然后才能执行此类操作。

代码语言:javascript
复制
//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

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5805479

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档