How to add a button to the Android Alert Dialog

Asked 2 years ago, Updated 2 years ago, 111 views

I made AlertDialog using a builder for the activity, but I want to put a button in it Okay, or whatever, you do something when the button is pressed Not the yes or no button by default. How can we do that?

android button builder alertdialog

2022-09-21 18:13

1 Answers

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Look at this dialog!")
       .setCancelable(false)
       .setPositiveButton("OK", new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int id) {
                //Button Click Action
           }
       });
AlertDialog alert = builder.create();
alert.show();

You can do it like this.


2022-09-21 18:13

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.