- // Set an `onClick` listener on the negative button.
- dialogBuilder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- // Do nothing if `Cancel` is clicked.
- }
- });
+ // Setup the negative button. Using `null` closes the dialog without doing anything else.
+ dialogBuilder.setNegativeButton(R.string.cancel, null);