Java 如何在 Android Studio 中显示弹出窗口以确认订单?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36747369/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 18:38:03  来源:igfitidea点击:

How to show a pop up in Android Studio to confirm an order?

javaandroidxmlandroid-studiopopup

提问by AldoT

I want to show a pop up or a prompt when a user makes an order in my app (pressing a button) for them to confirm the amount of the product and the price. How can I do that?? Some people say with a AlerDialog but I am not sure. This alert would have two buttons: "Confirm" and "Cancel".

当用户在我的应用程序中下订单(按下按钮)时,我想显示一个弹出窗口或提示,以便他们确认产品的数量和价格。我怎样才能做到这一点??有些人用 AlerDialog 说,但我不确定。此警报将有两个按钮:“确认”和“取消”。

Thanks in advace.

预先感谢。

采纳答案by Dus

AlertDialog suits your needs, and simple to implement.

AlertDialog 适合您的需求,并且易于实施。

   AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
            builder.setCancelable(true);
            builder.setTitle("Title");
            builder.setMessage("Message");
            builder.setPositiveButton("Confirm",
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                        }
                    });
            builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            });

            AlertDialog dialog = builder.create();
            dialog.show();

回答by Slobodan Antonijevi?

This: Dialogs | Android Developers

这:对话框 | 安卓开发者

What exactly are you not sure about? It's as simple as 1, 2, 3

你到底不确定什么?就像 1、2、3 一样简单

AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage(R.string.confirm_dialog_message)
           .setTitle(R.string.confirm_dialog_title)
           .setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int id) {
                   // CONFIRM
               }
           })
           .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int id) {
                   // CANCEL
               }
           });
    // Create the AlertDialog object and return it
    return builder.create();

回答by Developer SpiroSoft

You could use the alert builder for this:

您可以为此使用警报构建器:

new AlertDialog.Builder(context)
    .setTitle("Confirm Order")
    .setMessage("Are you sure?")
    .setPositiveButton(@"Confirm", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) { 
            // continue with delete
        }
     })
    .setNegativeButton(@"Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) { 
            // do nothing
        }
     })
    .setIcon(android.R.drawable.ic_dialog_alert)
     .show();