首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AlertDialog in onCreate

AlertDialog in onCreate
EN

Stack Overflow用户
提问于 2013-10-02 11:41:13
回答 1查看 470关注 0票数 0

我创建了一个AlertDialog in onCreate方法。我希望它只在类的第一次启动时显示。但问题是,当我改变设备的方向时,它会显示出来。由于应用程序的体系结构,我不能使用android:configChanges。当我改变方向时,有没有其他不显示AlertDialog的解决方案?谢谢。

下面是我如何在AlertDialog on onCreate上创建

代码语言:javascript
复制
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.module);
    new AlertDialog.Builder(MyActivity.this).setTitle("Activity")
        .setMessage("Alert?")
        .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) { 
                // do something
            }
         })
        .setNegativeButton("No", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) { 
                // do nothing
            }
         })
         .show();
    }
}
EN

回答 1

Stack Overflow用户

发布于 2013-10-02 13:37:39

只需将此android:configChanges="orientation|screenSize"添加到声明MyActivity的清单文件中即可。

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

https://stackoverflow.com/questions/19136072

复制
相关文章

相似问题

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