Android spinner with date picker, like Google Calendar app

Dash picture Dash · Feb 23, 2012 · Viewed 41.5k times · Source

I'm trying to get a text box that looks like a spinner to activate a date picker dialog. This is done in both the Google Calendar app and the Contacts app (for birthdate) on ICS. Do I need to use a spinner, and if so how do I change it's input view to be a date picker? Or if not, how do I get a text view to have the little triangle that usually indicates a spinner?

Answer

codinguser picture codinguser · Jun 4, 2012

Twaddington's comment on his answer is actually the right approach. What you need is to create a text view and apply the style

style="@android:style/Widget.DeviceDefault.Light.Spinner"

Then you can create a click listener on the text view and use it to open a DatePickerDialog. That can be accomplished as shown here: https://stackoverflow.com/a/8127571/332738 (If you follow the example, remember to add a default constructor to DatePickerDialogFragment so that your app does not crash on rotate)