4

I saw this question on stack overflow in several places, but the given answers does not work for me, so here I am :).

I need to set a date picker's minimum date dynamically to the current date. My minimum API is 12.

I tried this:

Calendar minCalendar = Calendar.getInstance();
minCalendar.set(Calendar.MILLISECOND, minCalendar.MILLISECOND - 1000);

DatePicker endDatePicker = (DatePicker) findViewById(R.id.datePicker2);
endDatePicker.setMinDate(minCalendar.getTimeInMillis());

I don't get any errors, only the date picker is not set to today. It is set to 'October 1964'....

Please help me...

EDITED

I also tried this, but the same effect:

endDatePicker.setMinDate(System.currentTimeMillis() - 1000);
Tünde
  • 885
  • 4
  • 11
  • 24

2 Answers2

1

From my similar question and answer:

// Calendar view is a cascade of bugs.
// Work around that by explicitly disabling it.
datePicker.setCalendarViewShown(false);

If a working calendar view with the date picker is a priority for you, I'd consider forking the platform code and fixing the bugs there.

Community
  • 1
  • 1
laalto
  • 150,114
  • 66
  • 286
  • 303
0

Try:

Time now = new Time();
now.setToNow();

DatePicker endDatePicker = (DatePicker) findViewById(R.id.datePicker2);
endDatePicker.setMinDate(now.toMillis(false));
TronicZomB
  • 8,667
  • 7
  • 35
  • 50