Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/183.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在安卓系统中,你如何向用户提示类似于吐司的消息?_Java_Android_Eclipse - Fatal编程技术网

Java 在安卓系统中,你如何向用户提示类似于吐司的消息?

Java 在安卓系统中,你如何向用户提示类似于吐司的消息?,java,android,eclipse,Java,Android,Eclipse,我希望用户通过向他们显示带有消息和“是”或“否”按钮的对话来确认操作。我如何使其显示,并根据他们选择的按钮执行操作 谢谢,AlertDialog看起来像我要找的。但是,有一个错误,它说“AlertDialog.Builder(this)”;“这告诉我,”构造函数AlertDialog.Builder(新视图.OnClickListener(){})未定义“–您要查找的是AlertDialog。使用该示例,您可以轻松创建一个“是/否”对话框,该对话框将显示以下内容: 创建一个新的AlertDial

我希望用户通过向他们显示带有消息和“是”或“否”按钮的对话来确认操作。我如何使其显示,并根据他们选择的按钮执行操作


谢谢,AlertDialog看起来像我要找的。但是,有一个错误,它说
“AlertDialog.Builder(this)”;“
这告诉我,
”构造函数AlertDialog.Builder(新视图.OnClickListener(){})未定义“

您要查找的是
AlertDialog
。使用该示例,您可以轻松创建一个“是/否”对话框,该对话框将显示以下内容:


创建一个新的
AlertDialog.Builder
,向其传递一些参数,最后调用其
create()
方法,并将返回值分配给
AlertDialog
对象以保存对它的引用

AlertDialog.Builder adb = new AlertDialog.Builder(this);
        adb.setTitle("Question");
        adb.setMessage(Html.fromHtml("Visit Stackoverflow?"));
        adb.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                // Action for YES
                startActivity(
                         new Intent(
                                Intent.ACTION_VIEW,
                                Uri.parse("http://www.stackoverflow.com")));
                return;
            }
        });

        adb.setNegativeButton("No", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                // Action for NO
                return;
            }
        });

AlertDialog myDialog = adb.create();
如图所示:

显示对话框调用

showDialog(DIALOG);
覆盖onCreateDialog,使用对话框ID的开关进行检查并插入

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Are you sure about this?")
   .setCancelable(false)
   .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
       public void onClick(DialogInterface dialog, int id) {
            // whatever if YES
       }
   })
   .setNegativeButton("No", new DialogInterface.OnClickListener() {
       public void onClick(DialogInterface dialog, int id) {
            // whetever if NO
       }
   });
AlertDialog alert = builder.create();
它很简单,如下所示

new AlertDialog.Builder(this)
            .setTitle("Info")
            .setMessage("hello")
            .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface arg0, int arg1) {
                    // Some stuff to do when ok got clicked                 
                }
            })
            .setNegativeButton("No", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface arg0, int arg1) {
                    // Some stuff to do when ok got clicked
                }
            })
            .show();

显然
System.err.println(“你喜欢烤面包吗?”):-)
new AlertDialog.Builder(this)
            .setTitle("Info")
            .setMessage("hello")
            .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface arg0, int arg1) {
                    // Some stuff to do when ok got clicked                 
                }
            })
            .setNegativeButton("No", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface arg0, int arg1) {
                    // Some stuff to do when ok got clicked
                }
            })
            .show();