0

我希望从使用 Square 的 TimeSquare 日期选择器日历的人那里得到一个例子。我希望禁用来年的所有周末日期。有人做到了吗?

谢谢

4

3 回答 3

1

查看源代码,尝试setDateSelectableFilter()

CalendarPickerView cpv=(CalendarPickerView)findViewById(R.id.whatever_you_called_it);

cpv.setDateSelectableFilter(new DateSelectableFilter() {
  @Override
  public boolean isDateSelectable(Date date) {
    int dow=date.get(Calendar.DAY_OF_WEEK);
    return (dow != Calendar.SATURDAY && dow != Calendar.SUNDAY);
  }
});
于 2017-05-13T11:24:16.440 回答
0

您可以使用下面的代码在 android-times-square calenderview 中制作周末假期,只需在 init 之前使用此代码。

calendar.setOnInvalidDateSelectedListener(null);
    calendar.setDateSelectableFilter(new DateSelectableFilter() {

        Calendar cal=Calendar.getInstance();
        @Override
        public boolean isDateSelectable(Date date) {
            boolean isSelecteable=true;
            cal.setTime(date);
            int dayOfWeek=cal.get(Calendar.DAY_OF_WEEK);        

                             //disable if weekend
            if(dayOfWeek==Calendar.SATURDAY || dayOfWeek==Calendar.SUNDAY){
               isSelecteable=false; 
            }
            return isSelecteable;
        }
    });
于 2018-06-13T07:04:05.927 回答
0

为了完整起见,并可能为其他人节省一些时间。这是完整的方法体

public void init(final Calendar calendar) {
    maxDate = calendar.getTime();
    calendarView.setOnInvalidDateSelectedListener(null);

    calendarView.setDateSelectableFilter(new DateSelectableFilter() {

        Calendar cal=Calendar.getInstance();
        @Override
        public boolean isDateSelectable(Date date) {
            boolean isSelectable=true;
            cal.setTime(date);
            int dayOfWeek=cal.get(Calendar.DAY_OF_WEEK);

            if(dayOfWeek==Calendar.SATURDAY || dayOfWeek==Calendar.SUNDAY){
                isSelectable=false;
            }
            return isSelectable;
        }
    });
    calendarView.init(new Date(), maxDate).withSelectedDate(new Date());

 }
于 2017-05-14T12:12:30.277 回答