仍然可以在日期选择器中选择禁用的日期 [英] Still able to select disabled dates in date picker
本文介绍了仍然可以在日期选择器中选择禁用的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在 android 中禁用日期选择器的过去日期.我可以通过使用
I want to disable the past dates of date picker in android. i can do it by using
dialog.getDatePicker().setMinDate(System.currentTimeMillis() - 1000);
这工作正常,日期选择器中的过去日期看起来已禁用.但是我仍然可以单击以前的日期并选择它.如何不让它发生?下面是我的日期选择器的屏幕截图:-
This is working fine and the past dates in date picker looks disabled. But I can still click on a previous date and select it. How to not let that happen ? below is the screenshot of my date picker :-
这是我禁用过去日期的代码:-
And here is my code where I am disabling the past dates :-
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
mActivity = new WeakReference<CreateEvent>(
(CreateEvent) getActivity());
DatePickerDialog dialog = new DatePickerDialog(getActivity(), this, year, month, day);
if(callingView==fromDate){
dialog.getDatePicker().setMinDate(System.currentTimeMillis() - 1000);
}else if (callingView==toDate){
dialog.getDatePicker().setMinDate(fromD);
}
// Create a new instance of DatePickerDialog and return it
return dialog;
}
推荐答案
从评论中得知这是 Lollipop 中的一个错误.所以,以编程方式修复它.
Got to know from a comment that this is a bug in Lollipop. So, fixed it programatically.
您需要做的就是检查所选日期和设置的最小日期.
All you need to do is check the selected date with the min date set.
这篇关于仍然可以在日期选择器中选择禁用的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文