Search code examples
androidandroid-alertdialogdatepickerdialog

DatePickerDialog display year picker first


I want my DatePickerDialog as soon as it opens to display the list of years.

For example, when I show the dialog I see the calendar view: calendar_view:

If I tap on the text "1900" the year view is shown: year_view

I tried this code but it had no effect and I'm clueless for what I could do: DatePickerDialog birthDatePicker = new DatePickerDialog(getActivity(), this, 0, 0, 0); birthDatePicker.getDatePicker().setSpinnersShown(true); birthDatePicker.show();


Solution

  • Using the Datepicker XML modifications you can elect to show spinners instead of the Calendar, which might be beneficial for you as you want to directly edit the years.

    android:datePickerMode="spinner"