android - 在 onCreate() 中显示对话框

标签 android dialog

根据特定条件,我可能需要显示一个对话框。在应用程序可以继续之前,必须解决此情况。基本上,我需要“暂停”我的程序的执行,直到这个对话框被销毁。我尝试了多种不同的方法,但遇到了应用程序继续执行的问题。目前,showDialog 在我的主要 Activity 的 onCreate() 方法中。

如有任何建议,我们将不胜感激。

最佳答案

如果您只想在按下按钮后运行代码,您应该使用“onClickListener”:

参见:http://developer.android.com/reference/android/app/AlertDialog.html#setButton(int , java.lang.CharSequence, android.content.DialogInterface.OnClickListener)

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.first_run_version_title)
    .setNeutralButton(R.string.ok_menu_button, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            // code to run here
        }
    });
AlertDialog alert = builder.create();
alert.show(); // <-- Forgot this in the original post

关于android - 在 onCreate() 中显示对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4300012/

相关文章:

java - 使用自定义适配器在 AlertDialog 中单击监听器

java - 对 token 感到困惑

android - 每次运行 Android 应用程序时都必须选择设备的替代方案?

java - 自定义共享对话框

jquery - 将 id 分配给 jquery 对话框按钮

c++ - 用 C 或 C++ 为 Android 编写应用程序?

android - sleep 后关闭锁定并打开屏幕

java - Facebook SDK 中的 R.Java 与应用程序 R.java 发生冲突

javascript - jquery ui 动态对话框

Delphi TFontDialog - 如何缩放高 Dpi?