Is it possible to disable certain weekdays in DatePickerDialog?

笑着哭i 提交于 2019-12-11 03:18:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!