CalendarView minimum date

你离开我真会死。 提交于 2019-11-28 11:38:55

问题


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

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