繁体   English   中英

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

[英]How to know which month and year is currently visible in CalendarView?

我正在开发一个基于 MaterialCalendarView (prolificinteractive) 的应用程序我正在用可绘制对象等装饰日子。我想知道用户当前可以看到哪个月份和年份,以便我只能将装饰器应用于当前可见月份而不是所有几个月,因为它会无缘无故减慢应用程序的速度。 注意:我不是在谈论当前选择的日期。

已经有一个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.
    }
});

或者更好的是,打开并发出或发出拉取请求,以在调用侦听器时将该字段公开并传递其值。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM