Search code examples
androidandroid-studiodatetimepickercustom-datetimepicker

How to set a custom minimum and maximum date selection day in "wdullaer materialdatetimepicker"


I am working on a project where I need to restrict the user from choosing any other dates than I want.

by reading some articles and SO post i tried the following which is supposed to work

    com.wdullaer.materialdatetimepicker.date.DatePickerDialog dpd = newInstance(
                ActivityClaimOffers.this,
                now.get(Calendar.YEAR),
                now.get(Calendar.MONTH),
                now.get(Calendar.DAY_OF_MONTH)
        );
    dpd.setMinDate(calendar);
    dpd.setMaxDate(calendar);

but I could not figure out how to pass custom dates as calendar objects. as both setMinDate() and setMaxDate() takes Calendar as parameter


Solution

  • Like this :

    Calendar calendar = new GregorianCalendar(year, monthOfYear, dayOfMonth);
    

    and for your code:

    dpd.setMinDate(new GregorianCalendar(2000, 5, 23));