[英]How to know which month and year is currently visible in CalendarView?
I am developing an app that is based on MaterialCalendarView (prolificinteractive) I am decorating days with drawables etc. I want to know which month and year is currently visible to the user so that I can only apply the decorater for the current visible month and not all the months as it will slow the app for no reason.我正在开发一个基于 MaterialCalendarView (prolificinteractive) 的应用程序我正在用可绘制对象等装饰日子。我想知道用户当前可以看到哪个月份和年份,以便我只能将装饰器应用于当前可见月份而不是所有几个月,因为它会无缘无故减慢应用程序的速度。 Note: I am not talking about the current selected date.
注意:我不是在谈论当前选择的日期。
There's a OnMonthChangedListener
already but it doesn't even have a month parameter, If you don't mind reflection: you can do this:已经有一个
OnMonthChangedListener
但它甚至没有月份参数,如果你不介意反思:你可以这样做:
calview.setOnMonthChangedListener((widget, date) -> {
try {
Field currentMonthField = MaterialCalendarView.class.getDeclaredField("currentMonth");
currentMonthField.setAccessible(true);
int currentMonth = ((CalendarDay) currentMonthField.get(widget)).getMonth();
// Do something, currentMonth is between 1 and 12.
} catch (NoSuchFieldException | IllegalAccessException e) {
// Failed to get field value, maybe library was changed.
}
});
Or better yet, open and issue or make a pull request to either make that field public on pass its value when the listener is called.或者更好的是,打开并发出或发出拉取请求,以在调用侦听器时将该字段公开并传递其值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.