问题
I need a DatePicker for a subscription service where the customer can select view dates. But not every day is available. For example on Wednesdays is no delivery.
Is it possible to disable specific week days?
Or do I have to make an alert afterwards to tell him this is not possible.
回答1:
in this project you will find the logic you need. DatePicker without sundays
Relevant snippet:
if (choosenDate.get(Calendar.DAY_OF_WEEK) ==
Calendar.SUNDAY ||
now.compareTo(choosenDate) < 0) {
dateTextView.setTextColor(
Color.parseColor("#ff0000")
);
((Button) dialog.getButton(
AlertDialog.BUTTON_POSITIVE))
.setEnabled(false);
} else {
dateTextView.setTextColor(
Color.parseColor("#000000")
);
((Button) dialog.getButton(
AlertDialog.BUTTON_POSITIVE))
.setEnabled(true);
}
You can rewrite this, of course, to block Wednesdays or any other days of the week. The code was written in the OnChangeListener of the Datepicker in the last java lines of the sample project.
回答2:
Here is one example for datepicker, display only week days and allow to select next 10days with active state. (Weekends disabled on selection)
$("#datepicker").datepicker({
format: "dd/mm/yyyy",
startDate: new Date(),
endDate: "+10d",
daysOfWeekDisabled: [0,6]
});
来源:https://stackoverflow.com/questions/31804941/is-it-possible-to-disable-certain-weekdays-in-datepickerdialog