Android - 如何使用Square的TimeSquare日历禁用周末的工作示例

时间:2017-05-13 10:46:09

标签: android datepicker calendar android-time-square

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

由于

3 个答案:

答案 0 :(得分:1)

查看源代码try 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);
  }
});

答案 1 :(得分: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());

 }

答案 2 :(得分: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;
        }
    });