Material-calendarview: scroll to selected date

Created on 28 Nov 2015  路  4Comments  路  Source: prolificinteractive/material-calendarview

When using setSelectedDate, it would be nice to have the calendar to scroll to that selected date or maybe have a function that could scroll the calendar to a specific date.

Most helpful comment

@fahimk @GerritHoekstra You can easily do this using mcv.setSelectedDate() paired with mcv.setCurrentDate()

All 4 comments

I hope this functionality is going to be implemented. Meanwhile I've fixed it:

if (currentMonth.getMonth() != day.getMonth()) {
    titleChanger.setPreviousMonth(currentMonth);
    // Find difference between months and move the view pager by that much
    int difference = currentMonth.getMonth() - day.getMonth();
    int newPosition;
    if(difference > 0) {
        newPosition = pager.getCurrentItem() + difference;
    } else {
        newPosition = pager.getCurrentItem() - difference;
    }
    pager.setCurrentItem(newPosition, true);
    currentMonth = adapter.getItem(newPosition);

    updateUi();
    dispatchOnMonthChanged(currentMonth);
} 

(Add this after line 658 in MaterialCalendarView.java)

@fahimk @GerritHoekstra You can easily do this using mcv.setSelectedDate() paired with mcv.setCurrentDate()

@quentin41500 Thans.... you save my day.

fist I use the mode that shows all dates in the calendar
when selecting a date form the next month it scrolls perfectly to the selected data
but when scroll back I found the selected date from the next month still selected
I know that the logic is correct in that case but that may confuse some users so
what about adding function to make that part optional for the developers ...

Was this page helpful?
0 / 5 - 0 ratings