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

34,458

Solution 1

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();

Solution 2

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();

Solution 3

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();
Share:
34,458
AldoT
Author by

AldoT

Updated on September 16, 2020

Comments

  • AldoT
    AldoT over 3 years

    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.

  • Slobodan Antonijević
    Slobodan Antonijević about 8 years
    "Delete entry"? Really? :)
  • Developer SpiroSoft
    Developer SpiroSoft about 8 years
    Its the sample code you can change the text according to your requirement.
  • AldoT
    AldoT about 8 years
    Thank you! That really helped me!! But I have another/last question... How can I change to another activity when I press the confirm button?? I tried with "startActivity" but it doesn't work. Thanks in advance!!!!
  • Dus
    Dus about 8 years
    startActivity is the right way to go, how exactly did you write it? are you sure you don't have any errors in the log ?