Android API 21 22 datepicker year selection error?

I have implemented a "calendar view" i.e. lollipop version of Android Datepicker. There's a difference between Android API 21 and 22 in choosing the year for the specified datepicker, when I click "2015" to change the year:

using API21

using API22

I am using the Nexus 5 simulator. I only see the current (2015) year in API22, whereas in API21 I can scroll from ~ 1950 to ~ 2100. Same code and, as far as I can tell, the same simulation settings.

I am wondering if this is just a bug, if someone else has run into it or has any tips for workaround? I really like the calendar view that Lollipop offers is so preferable if I can get it right to work. Will be updated with any new information I find.

+4


source to share


1 answer


Found a quick solution. Programmatically set the minimum and maximum dates for the DatePickerDialog object. I did it in the definition of the static DatePickerFragment class , so every DatePickerDialog instance is set:

DatePickerDialog datePickerDialog = new DatePickerDialog(getActivity(), YourActivityHere, year, month, day);
datePickerDialog.getDatePicker().setMinDate(datePickerDialog.getDatePicker().getMinDate());
datePickerDialog.getDatePicker().setMaxDate(datePickerDialog.getDatePicker().getMaxDate());

      



You can also set this if you have defined DatePickerDialog in the XML action, but I'm not sure if the error exists there.

+2


source







All Articles