【问题标题】:Alert Dialog Not Showing On MainActivty StartMainActivty 启动时未显示警报对话框
【发布时间】:2012-05-24 22:05:23
【问题描述】:

当我运行我的应用程序时,没有弹出对话框,是我遗漏了什么吗?

这是我的代码:

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("This is a test!")
   .setCancelable(false)
   .setPositiveButton("I Agree", new DialogInterface.OnClickListener() {
       public void onClick(DialogInterface dialog, int id) {
            MainScreen.this.finish();
       }
   })
   .setNegativeButton("I Disagree", new DialogInterface.OnClickListener() {
       public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
       }
   })
   //Set your icon here
   .setTitle("Alert!")
   .setIcon(R.drawable.ic_launcher);
AlertDialog alert = builder.create();

感谢所有帮助。

【问题讨论】:

    标签: android eclipse button dialog


    【解决方案1】:

    您应该在代码末尾调用alert.show()

    【讨论】:

      【解决方案2】:

      好的,我发现我必须输入 alert.show();在我的代码末尾。

      【讨论】:

        猜你喜欢
        • 2023-03-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-06-17
        • 1970-01-01
        • 1970-01-01
        • 2020-01-14
        相关资源
        最近更新 更多