问题
I created a CalendarView and I don't want to show previous months.
I tried this:
Calendar calendar = Calendar.getInstance();
int date = calendar.getActualMinimum(Calendar.DATE);
CalendarView calendar_view = (CalendarView) findViewById(R.id.calendar);
calendar_view.setMinDate(date);
Nothing seems to happen. The calendar works as normal.
回答1:
Try calculating the date like this:
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DATE,Calendar.getInstance().getActualMinimum(Calendar.DATE));
long date = calendar.getTime().getTime();
and set this as minimum date:
calendar_view.setMinDate(date);
since calendar_view.setMinDate(date) needs long value that represents milliseconds.
回答2:
calendar_view.setMinDate((new Date().getTime()));
works just fine
回答3:
You can just set the min date as below.
Calendar c = Calendar.getInstance();
CalendarView cv = (CalendarView)findViewById(R.id.calendarView);
cv.setMinDate(c.getTimeInMillis());
来源:https://stackoverflow.com/questions/20681605/calendarview-minimum-date