Android API 21 22 datepicker年度选择错误? [英] Android API 21 22 datepicker year selection bug?
问题描述
我已经实现了日历视图",即Android的Datepicker的棒棒糖版本. Android API 21&当我单击"2015"以更改年份时,在所述日期选择器的年份选择中选择22:
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:
我正在使用Nexus 5模拟器.我仅在API22中看到当前(2015年)条目,而在API21中,我可以从〜1950滚动到〜2100.据我所知,相同的代码和相同的仿真设置.
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.
我想知道这是否只是一个bug,是否有人遇到过bug,或有任何解决方法的提示?我真的很喜欢Lollipop提供的日历视图,如果我能正确地使用它的话,它是如此可取.将使用我发现的任何新信息进行更新.
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.
推荐答案
找到了快速解决方案.以编程方式设置DatePickerDialog对象的最小和最大日期.我是在 DatePickerFragment静态类定义中这样做的,所以每个DatePickerDialog实例都会被设置:
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());
如果您在XML活动中定义了DatePickerDialog,也可以进行设置,但是我不确定该错误是否存在.
You can also set this if you defined DatePickerDialog in an XML activity, but I'm not sure if the bug exists there.
这篇关于Android API 21 22 datepicker年度选择错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!