Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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".

Thanks in advace.

like image 310
AldoT Avatar asked Dec 08 '22 22:12

AldoT


2 Answers

AlertDialog suits your needs, and simple to implement.

   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();
like image 103
Dus Avatar answered Dec 10 '22 12:12

Dus


This: Dialogs | Android Developers

What exactly are you not sure about? It's as simple as 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();
like image 23
Slobodan Antonijević Avatar answered Dec 10 '22 11:12

Slobodan Antonijević