简体   繁体   English

如何知道 CalendarView 中当前可见的月份和年份?

[英]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.

相关问题 Android studio 如何从 CalendarView 获取 int 值(年、月、日)并用它保存在 SQLite 中 - Android studio How to get int value (year, month, day) from CalendarView and use it to save in SQLite 如何知道当前触发了哪个测试 - How to know which test is currently triggered 如何获取当前在回收站视图的线性布局中不可见的视图 - How to get the views which are not visible currently in the linear layout of the recycler view 如何强制Selenium WebDriver点击当前不可见的元素? - How to force Selenium WebDriver to click on element which is not currently visible? 如何根据焦点控件了解当前“焦点”在哪个顶部容器? - How to know which top container is currently “focused” according to the focused controls? 如何知道Apache Spark中当前正在运行的作业的哪个阶段? - How to know which stage of a job is currently running in Apache Spark? 如何知道访问期间ANTLR解析器当前处于哪个替代规则 - How to know which alternative rule ANTLR parser is currently in during visit 如何在具有月和年增量选项的检票口中使用DatePicker? - How to use DatePicker in wicket which have month and year increment option? CalendarView不显示该月的日期 - CalendarView not showing days of the month 是否可以知道当前打开的应用程序? - Is it possible to know the app which is opened currently?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM