Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android dialog setNegativeButton without listener

Tags:

People also ask

How do I get a yes no dialog box on Android?

setMessage( "Select yes to display toast message and no to dismiss the dialog ?" ) // button and setting text to it. // and setting text to it. // show to display our dialog.

Can you have an alert dialog without any buttons if not why?

You can do this very easily. AlertDialog. Builder alertDialogBuilder = new AlertDialog. Builder(context); // set title alertDialogBuilder.

How do I stop dialog closing?

Set the onClickListener during the creation of the dialog to null. Then set a onClickListener after the dialog is shown.

What is setPositiveButton Android?

setPositiveButton(int textId, DialogInterface.OnClickListener listener) Set a listener to be invoked when the positive button of the dialog is pressed. AlertDialog.Builder. setPositiveButton(CharSequence text, DialogInterface.OnClickListener listener)


Curiosity question here.

I use a lot of dialogs builders and most of the time my negative cancel button do nothing except dismiss the dialog. The code I found everywhere on the web is this :

builder.setNegativeButton(
    "cancel",
    new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    }
);

I happened to find out that this code do exactly the same :

builder.setNegativeButton("cancel", null);

So my question is then : is that a bad habit not to manually dismiss the dialog, and if yes why ?