android - 如何添加带有 'OK' 按钮的消息框?

标签 android messagebox

我想显示一个带有确定按钮的消息框。我使用了以下代码,但它会导致带有参数的编译错误:

AlertDialog.Builder dlgAlert  = new AlertDialog.Builder(this);
dlgAlert.setMessage("This is an alert with no consequence");
dlgAlert.setTitle("App Title");
dlgAlert.setPositiveButton("OK", null);
dlgAlert.setCancelable(true);
dlgAlert.create().show();

我应该如何在 Android 中显示消息框?

最佳答案

我认为您没有为确定正按钮添加点击监听器可能存在问题。

dlgAlert.setPositiveButton("Ok",
    new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
          //dismiss the dialog  
        }
    });

关于android - 如何添加带有 'OK' 按钮的消息框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6264694/

相关文章:

android - Android 模拟器设置中没有 "GPU emulation"选项

安卓录屏包括音频

在 Windows 7 上使用 GLUT 的 OpenGL,全屏模式不显示消息框

c# - MessageBox 没有获得焦点

带计时器的 C++ 对话框

Android - Drawable在不同的地方有不同的颜色

android - Looper 处理程序示例

android - 如何仅在退出应用程序时结束服务?

c++ - 如何更改 AfxMessageBox 中的语言?

c++ - 适用于 Linux 的类似 Windows 的消息框 - 这个 C++/Motif 实现是否可行?