I'm working with a DatePicker and finding that under Android 5.0 it will not call the OnDateChanged() method in its OnDateChangedListener when it's in CalendarView mode even though a new date has been selected. If android:datePickerMode="spinner" is set in the DatePicker's xml tag, the DatePicker will appear as spinners and it will call OnDateChanged() when a new date is selected. In earlier versions of Android, a DatePicker calls OnDateChanged() when a new date is selected in both CalendarView and Spinners versions. Here's the relevant code:
@SuppressLint("InflateParams")
View v = getActivity().getLayoutInflater().inflate(R.layout.dialog_date, null);
DatePicker datePicker = (DatePicker) v.findViewById(R.id.dialog_date_DatePicker);
datePicker.init(year, month, day, new DatePicker.OnDateChangedListener() {
@Override
public void onDateChanged(DatePicker view, int year, int month, int day) {
//Translate year, month, day into a Date object using a calendar
mDate = new GregorianCalendar(year, month, day).getTime();
//Update argument to preserve selected value on rotation
getArguments().putSerializable(EXTRA_DATE, mDate);
}
});
In my application, onDateChanged() doesn't get called and mDate doesn't get changed if the DatePicker is in CalendarView mode under Lollipop, but OnDateChanged() does get called and mDate does change if the DatePicker is in Spinners mode. Under earlier versions of Android, OnDateChanged() gets called and mDate gets changed in both versions of the DatePicker.
Is there any way to get a CalendarView DatePicker in 5.0 to call OnDateChanged()? Failing that, how else can I retrieve a changed date from the DatePicker when it's in CalendarView mode?