savvisingh / DateRangePicker

Date Range Picker is a Calendar Picker View to show a Customized Date Range Picker with improved UI and functionality to add subtitles to the dates
Apache License 2.0
785 stars 162 forks source link

Disable future dates #52

Open EdinHas opened 5 years ago

EdinHas commented 5 years ago

I need to disable all dates after today. If its 27th March I need to disable everything from 28th to the next 10 years. Is this possible?

Thanks.

AleeeAhmed commented 5 years ago

To disable future dates put 0 in nextYear calendar.

   final Calendar nextYear = Calendar.getInstance();
    nextYear.add(Calendar.YEAR, 0);

To disable past dates, you can set Year, Month, Day to 0.

    final Calendar lastYear = Calendar.getInstance();
    lastYear.add(Calendar.YEAR, 0);
    lastYear.add(Calendar.MONTH, 0);
    lastYear.add(Calendar.DAY_OF_MONTH, 0);

    ArrayList<Integer> list = new ArrayList<>();
    calendar.deactivateDates(list);

    ArrayList<Date> arrayList = new ArrayList<>();

    calendar.init(
            lastYear.getTime(),
            nextYear.getTime(),
            new Locale(LanguageCodes.ENGLISH))
            .inMode(CalendarPickerView.SelectionMode.RANGE)
            .withHighlightedDates(arrayList);