Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing "null" as DialogInterface.OnClickLIstener legit?

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.

like image 239
flxapps Avatar asked Aug 17 '14 16:08

flxapps


1 Answers

This is ok. This will simply dismiss the dialog which is what user wants when selecting cancel option.

like image 130
Vasudev Avatar answered Oct 31 '22 12:10

Vasudev