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.
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.