在Android日期选择器中禁用特定日期 [英] Disable specific dates of day in Android date picker
本文介绍了在Android日期选择器中禁用特定日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用datePicker,我可以通过以下代码禁用今天和30天后的最后几天:
I'm using the datePicker and I can disable last days of today and later days after 30 days by the following code:
DatePickerDialog datePicker = new DatePickerDialog();
Calendar calender = Calendar.getInstance();
long today = calender.getTimeInMillis();
final long oneDay = 24 * 60 * 60 * 1000L;
Date previousDays = new Date(today - 1000);
datePicker.setMinDate(DateToCalendar(previousDays));
Date nextMonth = new Date(today + 30 * oneDay);
datePicker.setMaxDate(DateToCalendar(nextMonth));
如果我要禁用每个月的星期五,我该怎么做?
If I want to disable Friday of every month, how can I do this?
推荐答案
这是不可能的android datepicker,你需要为自己创建一个自定义选择器。请参阅 MaterialDateTimePicker
That is not possible with the android datepicker and you need to create a custom picker for yourself. See MaterialDateTimePicker
要禁用星期日您有通过这样的数组
To disable Sundays you have to pass the array like this
List<Calendar> dayslist= new LinkedList<Calendar>();
Calendar[] daysArray;
Calendar cAux = Calendar.getInstance();
while ( cAux.getTimeInMillis() <= gc.getTimeInMillis()) {
if (cAux.get(Calendar.DAY_OF_WEEK) != 1) {
Calendar c = Calendar.getInstance();
c.setTimeInMillis(cAux.getTimeInMillis());
dayslist.add(c);
}
cAux.setTimeInMillis(cAux.getTimeInMillis() + (24*60*60*1000));
}
daysArray = new Calendar[dayslist.size()];
for (int i = 0; i<daysArray.length;i++)
{
daysArray[i]=dayslist.get(i);
}
datePickerDialog.setSelectableDays(daysArray);
这篇关于在Android日期选择器中禁用特定日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文