Skip to content

Commit 43792f8

Browse files
committed
[DatePicker] Make the month buttons navigate through months, not pages
1 parent 015e053 commit 43792f8

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

lib/java/com/google/android/material/datepicker/MaterialCalendar.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -495,22 +495,14 @@ public void onClick(View view) {
495495
}
496496
});
497497

498-
monthNext.setOnClickListener(
499-
new OnClickListener() {
500-
@Override
501-
public void onClick(View view) {
502-
int currentItem = getLayoutManager().findFirstVisibleItemPosition();
503-
setCurrentMonth(monthsPagerAdapter.getPageMonth(currentItem + 1));
504-
}
505-
});
506-
monthPrev.setOnClickListener(
507-
new OnClickListener() {
508-
@Override
509-
public void onClick(View view) {
510-
int currentItem = getLayoutManager().findLastVisibleItemPosition();
511-
setCurrentMonth(monthsPagerAdapter.getPageMonth(currentItem - 1));
512-
}
513-
});
498+
monthNext.setOnClickListener(view -> {
499+
Month currentMonth = getCurrentMonth();
500+
setCurrentMonth(currentMonth.monthsLater(1));
501+
});
502+
monthPrev.setOnClickListener(view -> {
503+
Month currentMonth = getCurrentMonth();
504+
setCurrentMonth(currentMonth.monthsLater(-1));
505+
});
514506

515507
int currentMonthPosition = monthsPagerAdapter.getPosition(current);
516508
updateNavigationButtonsEnabled(currentMonthPosition);

0 commit comments

Comments
 (0)