title: How to auto dismiss() or cancel() or hide() Datepicker after selecting the Date from the Datepicker dialog without the OK click button in Android
body: <p>I want to dismiss() the Dialog of Date Picker after selecting the Date from the DatePicker, But I didn't get what I want, as well as I have search on google but unsuccessful. The below is the code I want to try to hide the Datepicker.</p>
  
  <pre><code>public static class DatePickerFragmentDepartureDate extends DialogFragment implements DatePickerDialog.OnDateSetListener {
      @Override
      public Dialog onCreateDialog(Bundle savedInstanceState) {
          Calendar calendar = Calendar.getInstance();
          int year = calendar.get(Calendar.YEAR);
          int month = calendar.get(Calendar.MONTH);
          int day = calendar.get(Calendar.DAY_OF_MONTH);
  
          DatePickerDialog dpd = new DatePickerDialog(this.getActivity(), this, year, month, day);
          dpd.getDatePicker().setMinDate(new Date().getTime() - (new Date().getTime() % (24 * 60 * 60 * 1000)));
          return dpd;
      }
  
      @Override
      public void onDateSet(DatePicker view, int year, int month, int day) {
          // Do something with the chosen date
          TextView tv = (TextView) this.getActivity().findViewById(R.id.departureDate);
          // Create a Date variable/object with user chosen date
          Calendar cal = Calendar.getInstance();
          cal.setTimeInMillis(0);
          cal.set(year, month, day, 0, 0, 0);
          Date chosenDate = cal.getTime();
          // Format the date using style and locale
          DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.US);
          String formattedDate = df.format(chosenDate);
          formattedDate = (month + 1) + "#" + day + "#" + year;
          // Display the chosen date to app interface
          tv.setText(formattedDate);
      }
  }
  </code></pre>
  
  <p>Your answers and help will be appreciated. Thanks</p>