Android DatePicker in spinner mode not showing date

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


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.


DatePicker


DatePickerDialog



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)


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?


DatePickerDialog



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!


DatePicker


datePicker.updateDate


datePicker.setMaxDate


setMaxDate



Any solution/suggestion appreciated.





Why do you use now().minusMinutes( DATE_PICKER_MIN_DATE_OFFSET_IN_MIN).getMillis() ); (now()) and after an older time than less is sure than now so this can create bug. If you take time and the app need more than one min they will crash. I suggest you use activationDateTime instead of now()
– crammeur
Jul 26 at 4:03


now().minusMinutes( DATE_PICKER_MIN_DATE_OFFSET_IN_MIN).getMillis() );


now()


activationDateTime


now()





I need the spinner from system date to activation date. That's why now() is used. And I don't face any problem with the min. Problem happens when the Max value is updated as current to the DatePicker
– VishnuSP
Jul 26 at 4:10




now()


DatePicker





In the min value? and activationDateTime is in the futur or past compare to now()
– crammeur
Jul 26 at 4:13




min


activationDateTime


now()





yes, activationDateTime is in future which is set as max. Also updating the same as current date to show when picker is launched.
– VishnuSP
Jul 26 at 4:19


activationDateTime





@VishnuSP I think it is going beyond the max limit of picker when you set month as Aug. What is your max date?
– Pankaj Kumar
Jul 26 at 11:00




1 Answer
1



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


DatePicker


spinner



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






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Makefile test if variable is not empty

Will Oldham

Visual Studio Code: How to configure includePath for better IntelliSense results