How to configure DatePicker for date of birth date selection

Ollie C picture Ollie C · Oct 18, 2017 · Viewed 8.8k times · Source

With the default display the DatePicker shows the current month, but the user may wish to select a date which is hundreds of months previous. It is of course possible to tap the year and select the birth year that way, but many users are not aware of this and most are clicking through the months to go back years to select the date of birth. It is causing a great deal of frustration.

Is there a way to configure the Android DatePicker so that when it opens it asks the user to select the year first? Or is there a way of displaying the months so the user can slide through them more quickly rather than click? Or is it really necessary to create a UI in advance of the date picker to require them to select the year before the DatePicker opens? I find the DatePicker, for selecting dates some time ago, is very poor as its ease of use requires use of a feature that many users are just not aware of.

Answer

Ollie C picture Ollie C · Oct 19, 2017

The last three attributes on the DatePicker below do the trick, as it switches the DatePicker from the "Calendar" view to use the three spinners for year, month and day:

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