Passing "null" as DialogInterface.OnClickLIstener is legal?

Just a quick question: I just found out that

new AlertDialog.Builder(this) .setTitle("Hi") .setMessage("Some text. Did you read it?") .setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // do something } }) .setNegativeButton("No, I'm too lazy", null) .show(); 

works well on my device. Passing a null value as DialogInterface.OnClickListener simply rejects the dialog. I wanted to ask if this is legal or can cause problems, for example, on older Android devices / versions? I did not find anything in the documentation.

I have never done this yet, but it saves some code and makes sense, in my opinion. So far, I have always created an OnClickListener to reject the dialog. It does not seem to be necessary.

+6
source share
1 answer

This is normal. This will simply disable the dialog box that the user requires when choosing the undo option.

+4
source

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


All Articles