Skip to content Skip to sidebar Skip to footer

Lollipop Calenderview Datepicker Doesn't Call Ondatechanged() Method

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

Solution 1:

I face the same issue and the thing is onDateChange() and onTimeSet() listeners for DatePicker and TimePicker is not called in Nexus devices with lollipop Update.

The reason is in nexus devices, since the clock app is updated, the listeners are not working.

The work around is once the dialog dismiss, you need to create you own listener and set the values in a calendar object using the datepicker get() methods and pass the calendar to the listener.

A simple sample code is

/**
 * Returns the calendar instance once the date and time is set.
 * @return
 */
public Calendar getDateTime() {
    mCalendar.set(datePicker.getYear(),
                  datePicker.getMonth(),
                  datePicker.getDayOfMonth(),
                  timePicker.getCurrentHour(),
                  timePicker.getCurrentMinute());
    return mCalendar;
}

Solution 2:

Set this in your Xml-Layout:

<DatePicker
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:datePickerMode="spinner"
        android:spinnersShown="false"
        android:id="@+id/datepicker_popupwindow"/>

With "android:spinnersShown="false" " you tell it to not show the Spinner. But it will call the 'onDateChanged' Method.

Post a Comment for "Lollipop Calenderview Datepicker Doesn't Call Ondatechanged() Method"