Search code examples
androidandroid-datepicker

Max Date on an Android DatePickerDialog


I need to set a max year on the DatePickerDialog that I am using but I am unable to find any mechanism of doing that. The documentation mentions getDatePicker () as a public method of the DatePickerDialog. So, I thought, perhaps, that can be used to get the DatePicker and then I could set the max date but I get "Method undefined" error when I try to get the DatePicker.

This is how I am trying to get the DatePicker inside my onCreateDialog.

DatePickerDialog d = new DatePickerDialog(this, dep_dateListener, mYear,
                      mMonth, mDay);
DatePicker dp = d.getDatePicker();
dp.setMaxDate(maxDate);
return d;

Any pointers on how to do this?

Thanks


Solution

  • The getDatePicker() method is available in API Level 11.