![](/img/trans.png)
[英]Android studio How to get int value (year, month, day) from CalendarView and use it to save in SQLite
[英]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.