How to programmatically change DatePicker and TimePicker to display in 'Calendar'-mode (or 'Clock'-mode, resp.) or 'Spinner'-mode?
My Android application is using android.widget.DatePicker and android.widget.TimePicker in several places. I would like to give the user the option to choose whether they want to display that dialog in "Calender-mode" or "Spinner-mode" (or in "Clock-mode" or "Spinner-mode", resp., for TimePicker).
I found misc. appends (e.g. https://stackoverflow.com/questions/34723495/how-to-set-datepickermode-spinner-programmatically) and following these I am calling:
datePicker.setSpinnersShown(true);
datePicker.setCalendarViewShown(false);
(for spinner mode or vice versa, for the other mode).
But these calls have no effect whatsoever on the rendering of the DatePicker.
What am I missing?
Later addition:
I just found out that if I declare the DatePicker initially to use spinner-mode like so:
<DatePicker
android:id="@+id/datePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:datePickerMode="spinner"
/>
... then the calls do work and actually switch the display mode.
But the downside of this approach is, that the entire widget looks strange, i.e. it's shown with wrong height (the header is missing and the calendar is truncated at the bottom):
Calendar mode:
Spinner mode:
... instead of the proper display showing a header with the currently selected date:
This widget seems pretty buggy to me... :-(
Second addition:
The DatePicker-widget really sucks! In order to work around the non-working setXYZShown(...)-methods I created a new layout where I define TWO DatePickers (one in calendar mode and the other in spinner mode) with the intention to always show only one and hide the other depending on the user's selected preference. Same for the TimePicker dialog.
The switching now works and for the TimePicker this now displays as desired:
in Clock mode (clock mode widget "visible" / spinner mode widget "gone"):
vs. Spinner mode (i.e. clock mode widget "gone" / spinner mode widget "visible"):
But the DatePicker widget only displays OK in Calendar mode (i.e. calendar mode widget "visible" / spinner mode widget "gone"):
but displays a fuzzy mixture of spinner and calender mode when I switch it to spinner mode (i.e. calendar mode widget "gone" / spinner mode widget "visible"):
I first thought that my hiding/unhiding logic has some bug but that's not the case! The above display is from a DatePicker-widget showing in Spinner mode! What's esp. annoying is that the year-spinner isn't even visible in vertical mode, only when one turns the display sideways it appears:
But that calendar display to the right that shouldn't be there is still visible!
What a buggy widget this is! :-(