如何添加消息框,确定按钮 [英] how to add message box with ok button

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

问题描述

我想有一个确定按钮显示一个消息框。我用下面的code,但它会导致编译错误与参数:

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天全站免登陆