如何使用“确定"按钮添加消息框? [英] How to add message box with 'OK' button?

查看:127
本文介绍了如何使用“确定"按钮添加消息框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to display a message box with an OK button. I used the following code but it results in a compile error with argument:

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中显示消息框?

How should I go about displaying a message box in Android?

推荐答案

我认为您可能还没有为确定按钮添加点击监听器.

I think there may be problem that you haven't added click listener for ok positive button.

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

这篇关于如何使用“确定"按钮添加消息框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆