Search code examples
androiddatepickerandroid-datepicker

Android DatePicker in spinner mode not showing date


I'm using DatePicker in spinner mode, and sets min and max limit. Then updates the date as max value. Date column does not have a value when the DatePickerDialog shown. When I tap/scroll up or down the values are shown.

MyLayout:

         <DatePicker
                android:id="@+id/date_picker"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginLeft="@dimen/spacing_default"
                android:layout_marginRight="@dimen/spacing_default"
                android:datePickerMode="spinner"
                android:calendarViewShown="false" />

Java Part : (in onViewCreated)

 private static final int DATE_PICKER_MONTH_OFFSET = 1;
 private static final int DATE_PICKER_MIN_DATE_OFFSET_IN_MIN = 1;

datePicker.setMinDate( now().minusMinutes( 
         DATE_PICKER_MIN_DATE_OFFSET_IN_MIN).getMillis() );
datePicker.setMaxDate( activationDateTime.getMillis() );
datePicker.updateDate( activationDateTime.getYear(), 
         activationDateTime.getMonthOfYear() - DATE_PICKER_MONTH_OFFSET,
                    activationDateTime.getDayOfMonth() );

Problematic Screenshot:

enter image description here

What more is needed to make the date part to be displayed when the DatePickerDialog is shown?

UPDATE/EDIT:

The seems that picker show an empty view when the value set is same as the max limit. I could resolve the issue (while launching the DatePicker) by placing datePicker.updateDate first and then call datePicker.setMaxDate. The setMaxDate will validate the previously value and sets correctly. But now I face the same problem when I scroll the month from Jul to Aug, the day view becomes empty!

Any solution/suggestion appreciated.


Solution

  • There seems to have bug in the android widget DatePicker in the spinner mode. Already such a ticket present in the Google issue tracker also : https://issuetracker.google.com/issues/64508670

    Unfortunately no work around or suggestions available in the issue tracker.