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 as DialogInterface.OnClickListener simply dismisses the dialog. I wanted to ask, if this is legit or might cause problems for example on older devices / Android versions? I did not find anything in the documentation.
I never did it that way until now, but it saves some code and makes sense in my opinion. Until now, I always created a OnClickListener to dismiss the dialog. Kinda unnecessary it seems.
This is ok. This will simply dismiss the dialog which is what user wants when selecting cancel option.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With