【发布时间】:2018-02-12 17:41:24
【问题描述】:
我正在使用 materialdatetimepicker 来自定义我的日历。 我的要求是我想禁用今天和接下来 31 天的所有日期。
我尝试过的。
1 - 将最短日期设置为今天 - datePickerDialog.setMinDate(now);
2 - 从今天起最多 31 天。 - datePickerDialog.setMaxDate(cal);
3 - 禁用两者之间的日期。 datePickerDialog.setDisabledDays(otherCalendars);
当我一起执行第 1 步、第 2 步和第 3 步时,日历根本没有打开并且应用程序冻结。
当我分别执行步骤 (1,2) 和 3 时,我得到了正确的结果。但我只想从现在开始显示接下来的 31 天并禁用它们。
这是我尝试过的代码。
我哪里弄错了?非常感谢任何帮助。
private DatePickerDialog datePickerDialog;
DateTime startDateTime = new DateTime();
DateTime endDateTime = new DateTime();
endDateTime = endDateTime.plusDays(31);
List<DateTime> otherDays = new ArrayList<>();
while (startDateTime.isBefore(endDateTime)) {
otherDays.add(startDateTime);
startDateTime = startDateTime.plusDays(1);
}
Calendar[] otherCalendars = new Calendar[otherDays.size()];
for (int count = 0; count < otherDays.size(); count++) {
otherCalendars[count] = otherDays.get(count).toGregorianCalendar();
}
datePickerDialog.setMinDate(now);
Calendar cal = Calendar.getInstance();
Date ddd = endDateTime.toDate();
cal.setTime(ddd);
datePickerDialog.setMaxDate(cal);
datePickerDialog.setDisabledDays(otherCalendars);
谢谢 回复
【问题讨论】:
标签: android datetime android-calendar android-datepicker