Search code examples
androidandroid-5.0-lollipopandroid-datepicker

Android API 21 22 datepicker year selection bug?


I've implemented the "calendar view", i.e., lollipop version of Android's Datepicker. There's a difference between Android API 21 & 22 in the year selection of said datepicker when I click on "2015" to change the year:

using API21

using API22

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

I'm wondering if this is just a bug, if anyone else has encountered it, or has any tips for a workaround? I really like the calendar view that Lollipop offers so preferable if I can get this working right. Will update with any new information I find.


Solution

  • Found a quick fix. Programmatically set the min and max dates of the DatePickerDialog object. I did so in the DatePickerFragment static class definition, so every instance of DatePickerDialog gets 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 defined DatePickerDialog in an XML activity, but I'm not sure if the bug exists there.