setMinDate() for DatePicker [duplicate]

廉价感情. 提交于 2019-12-23 12:01:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!