【问题标题】:Disables set of dates using materialdatetimepicker使用 materialdatetimepicker 禁用日期集
【发布时间】: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


    【解决方案1】:

    我遇到了同样的问题,并在这里找到了解决方案 Disable whole week except weekend in calender [disable-whole-week-except-weekends]

    我使用 List 和 Calendar 类型 List&lt;Calendar&gt; weekends = new ArrayList&lt;&gt;(); 并填写我想禁用的日子。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-15
      • 2019-12-27
      相关资源
      最近更新 更多