How do I detect a cancel click of the datepicker dialog?

Here’s how I did it:

  DatePickerDialog dialog = new DatePickerDialog(this,
              mDateSetListener,
              year, month, day);

  dialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.cancel), new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int which) {
       if (which == DialogInterface.BUTTON_NEGATIVE) {
          // Do Stuff
       }
    }
  });

Leave a Comment