Skip to content Skip to sidebar Skip to footer

Setmindate(...) For Datepicker Doesn't Work When Invoked A Second Time

I'm in a particular situation in which I have to alter the min and max date of DatePicker according to the selected element of a Spinner. Here's the chunk of code I'm using to swit

Solution 1:

This happens because method setMinDate() has check

if (mTempDate.get(Calendar.YEAR) == mMinDate.get(Calendar.YEAR)
                && mTempDate.get(Calendar.DAY_OF_YEAR) != mMinDate.get(Calendar.DAY_OF_YEAR){
            return;
 }

Simple workaround is to set min date with different year at first, for example

mPicker.setMinDate(0);

mPicker.setMinDate(new LocalDate().minusWeeks(2)
                                .toDateTimeAtStartOfDay().getMillis());

It works for me.

Solution 2:

As said above, you can bypass the check by calling those before actually changing the value:

setMinDate(0);
setMaxDate(Long.MAX_VALUE);

If you want to reset the minimum or maximum value to its default, you can use the following values:

setMinDate(-2208902400000L);  // Jan 1, 1900setMaxDate(4102531200000L);  // Jan 1, 2100

Solution 3:

first update setMinDate to 0 after then setMinDate according to you dateobject

mPicker.setMinDate(0);

mPicker.setMinDate(datepickerObject.getTimeInMillis());

Solution 4:

mPicker.setMinDate(0);

doesn't work for me.

Try to reinitialize the picker.

mPicker = new DatePickerDialog(..)

Post a Comment for "Setmindate(...) For Datepicker Doesn't Work When Invoked A Second Time"