Reputation: 1229
I have a DatePickerDialog (com.wdullaer.materialdatetimepicker.date) that has its selectableDays populated from an API. The API that we use only supports retrieving one month at a time. As a result, we need to retrieve more selectableDays for the next month when the user taps the arrow to go to the next month. (Circled in red in the attached image)
We accomplish this by keeping a global list of calendars and adding additional Calendars from the network responses:
val selectableCalendars = HashSet<Calendar>() // List of available appointment dates (including time)
That works fine, but when DatePickerDialog is open and the following line runs to change the selectable days:
datePickerDialog.selectableDays = selectableCalendars.toTypedArray()
The DatePickerDialog will jump back to the first month in the calendar list.
This "jump back to June" (unintended behavior) always occurs under the following circumstances:
1.) Immediately after we set datePickerDialog.selectableDays to a new value.
2.) Only if there are no selectable days for the month the user scrolled into. (Bug does not occur if there are selectable days in the returned month!)
Does anyone have a workaround for this issue?
Upvotes: 1
Views: 49
Reputation: 1938
By checking the code here
It seems that after you set new selectableDays, the refresh function will take current selected day position and scroll back to it https://github.com/wdullaer/MaterialDateTimePicker/blob/f849a5c2704c974ba182fe4e2e205fa7f4fd395d/library/src/main/java/com/wdullaer/materialdatetimepicker/date/DayPickerView.java#L142
So my proposal will be setting the mSelectedDay
to the first day of the month when user scoll to the next month. Which I think also not a great user experience.
I would also recommend to post this question on author's github page, or search for similar question/issue/bug history in the library github pag
Upvotes: 1