AlertDialog does not show two buttons

AlertDialog does not display the submit button. Below is the code. Please tell me what mistake I made in my code.

protected Dialog onCreateDialog(int id) {
    final AlertDialog.Builder dialog = new AlertDialog.Builder(this);
    dialog.setMessage("Enter Holla message");
    EditText hollaMessage = new EditText(this);
    dialog.setView(hollaMessage);
    dialog.setCancelable(false);
    dialog.setPositiveButton("Send", new DialogInterface.OnClickListener() {
       public void onClick(DialogInterface dialog, int id) {
          List result = new ArrayList();
       }
    });
    dialog.setPositiveButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dismissDialog(0);
        }
    });
    AlertDialog alert = dialog.create();
    return alert;
}
+3
source share
3 answers

You set the positive button twice .. do it setNagativeButton("Cancel".....

protected Dialog onCreateDialog(int id)
{
    final AlertDialog.Builder dialog = new AlertDialog.Builder(this);
    dialog.setMessage("Enter Holla message");
    EditText hollaMessage = new EditText(this);
    dialog.setView(hollaMessage);
    dialog.setCancelable(false);
    dialog.setPositiveButton("Send", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            List result = new ArrayList();
        }
    });
    dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dismissDialog(0);
        }
    });
    AlertDialog alert = dialog.create();
    return alert;
}
+4
source

about! Buddy also has the ability to add a neutral button.
You can add a neutral button that looks like a positive and negative button.

Now your next comment will be if I want to add 2 buttons 4?

Then just make a layout in xml of all four buttons and inflate it 2, set it in the dialog box.

... .
.

+3

add ".show ()" to the end of any button. for exam:

dialog.setPositiveButton("Cancel", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int which) {
        dismissDialog(0);
    }
}).show();
0
source

Source: https://habr.com/ru/post/1790145/


All Articles