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
The getDatePicker() method is available in API Level 11.
to make a subclass of DatePickerDialog
override onDateChanged method
see the source code
A better implementation in monodroid:
setMaxDate()
is only useful for new APIs but if you want your application to work with earlier versions then you have to make your own comparator for dates.For example I just get the local date using
Calendar.getInstance()
and using the methodDate.before(Date)
ORDate.after(Date)
you can add restrictions forDatePicker
.