问题
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);
回答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.
回答2:
Try:
Time now = new Time();
now.setToNow();
DatePicker endDatePicker = (DatePicker) findViewById(R.id.datePicker2);
endDatePicker.setMinDate(now.toMillis(false));
来源:https://stackoverflow.com/questions/16859192/setmindate-for-datepicker