How to disable specific dates in calendar

强颜欢笑 提交于 2019-12-14 03:32:33

问题


How can I disable specific dates? I don't mean previous or future dates, but rather specified dates such as holidays.


回答1:


How to disable specific dates in calendar

AFAIK No You can't disable specific dates in calendar because that is That is not a built in behavior

for that purpose you have to use third party library or your have to create your own

you would have to use a custom date picker.




回答2:


At last found it.. how to disable specified dates in calendar..

    SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
                    String a = "26-07-2017";
                    java.util.Date date = null;
                    try {
                        date = sdf.parse(a);
                        MainActivity obj = new MainActivity();
                        calendar = obj.dateToCalendar(date);
                        System.out.println(calendar.getTime());
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }

                    List<Calendar> dates = new ArrayList<>();
                    dates.add(calendar);
                    Calendar[] disabledDays1 = dates.toArray(new Calendar[dates.size()]);
                    dpd.setDisabledDays(disabledDays1);

private Calendar dateToCalendar(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar;
    }



回答3:


For enabling specified dates in a calendar, you can use this library.

Here if you will see the DatePickerFragment in the sample. We are passing an array of calendar dates like this.

               Calendar[] days = new Calendar[13];
                for (int i = -6; i < 7; i++) {
                    Calendar day = Calendar.getInstance();
                    day.add(Calendar.DAY_OF_MONTH, i * 2);
                    days[i + 6] = day;
                }
               dpd.setSelectableDays(days);

We can create the array of calendar dates in specified format and pass that calendar dates array to the date picker dialog to enable it.

You can achieve your goal in similar way.



来源:https://stackoverflow.com/questions/44650053/how-to-disable-specific-dates-in-calendar

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