I'm hoping to get a an example from someone who worked with Square's TimeSquare date-picker calendar. I wish to disable all the weekend dates for the coming year. Anyone achieved this?
Thanks
I'm hoping to get a an example from someone who worked with Square's TimeSquare date-picker calendar. I wish to disable all the weekend dates for the coming year. Anyone achieved this?
Thanks
Looking at the source code, 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);
}
});
For the sake of completeness and possibly save others some time. Here is the full, complete method body
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());
}
You can use below code for making weekends off in android-times-square calenderview, Just use this code before 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;
}
});