calendarview highlights wrong week

余生颓废 提交于 2020-01-13 16:27:23

问题


I have a CalendarView in my app, when the user selects a date by touching that date in the monthview, the correct date is selected (verified by adding debug statements in the code), but the week before is highlighted, so it looks as if the wrong date is selected.

I have found a work-around: if I set 'firstDayInWeek' to 1 the problem is solved, but by default the firstDayInweek is 2 (monday), and then this problem occurs.

Thank you very much!

Samsung S4 with API 21


回答1:


I have had the same issue as you, using a Samsung S5 running API 21.

There are two workarounds that I have found, none of them is a good experience for our users :(

  1. Force first day of the week to Sunday

    calendarView.setFirstDayOfTheWeek(Calendar.SUNDAY);
  1. Set a minimum and a maximum date for the calendar (be careful because not all of the dates work here). I was able to make it work properly setting a minimum date 2 months before the current date and maximum date 2 years after the current date. You can play with these values and find a good compromise between the limits and your user experience.

    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 2);
    calendarView.setMinDate(calendar.getTimeInMillis());
    calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) + 2);
    calendarView.setMaxDate(calendar.getTimeInMillis());

Unfortunately, this is the only way I could fix this issue, I hope it is useful for you.



来源:https://stackoverflow.com/questions/30174539/calendarview-highlights-wrong-week

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