AndroidNegativeButton dialog box without listener

Question about curiosity.

I use many dialog box developers, and most of the time my cancel button cancels nothing but rejecting the dialog. The code I found throughout the Internet 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 does the same:

builder.setNegativeButton("cancel", null);

So my question is: is it a bad habit not to manually reject the dialogue, and if so, why?

+4
source share
2 answers

This is a somewhat documented behavior, see:
http://developer.android.com/guide/topics/ui/dialogs.html#DismissingADialog

, AlertDialog.Builder, .

, Dialog.

? (, , 50% , - ROM ... , , , , BS).

+3

Android . , , .

"" , .

+1

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


All Articles