Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Calendar View for Date Picker

I'm writing my first app, and I have a question about DatePicker.

My app requires the user to input a date. The most user-friendly way would be to popup a calendar-like widget that displays the current month like a calendar grid - something like this:

enter image description here

I want to use that in place of the DatePicker interface - which has Month, Day, and Year fields, each with an up and down button to increment/decrement.

Is this type of functionality built into any Android widget or view, or would I have to design my own custom component to do this? I figured this would already exist, seeing how much this type of UI is used so frequently in non-mobile apps and web pages.

Thanks!

like image 268
ndtrek07 Avatar asked Sep 14 '10 20:09

ndtrek07


People also ask

How do I set calendar view in android?

Step 1: Create a new project and you will have a layout XML file and java file. Your screen will look like the image below. Step 2: Open your xml file and add CalendarView and TextView. And assign id to TextView and CalendarView.

Is DatePickerDialog class available in android?

Android Date Picker allows you to select the date consisting of day, month and year in your custom user interface. For this functionality android provides DatePicker and DatePickerDialog components.

What is the use of DatePicker view in android?

Android provides controls for the user to pick a time or pick a date as ready-to-use dialogs. Each picker provides controls for selecting each part of the time (hour, minute, AM/PM) or date (month, day, year).


1 Answers

Now, in 2014, even the native DatePicker (link) contains small Holo looking CalendarView (link) to pick a day in month.

You can choose, if both spinners and CalendarView or just one of them is displayed by setting:

  • android:calendarViewShown
  • android:spinnersShown

I'm not sure if it's just API level 16+ or if it was even in Ice Cream Sandwich, but it's there. This is how it looks by default:

enter image description here


Moreover, on API level 21 and higher there is a new Material themed DatePicker that looks like following:

enter image description here

This is default on API 21+ and there are no spinners anymore, but you can switch back to the Holo one by setting

android:datePickerMode="spinner" 

in your XML.

like image 186
Marcel Bro Avatar answered Oct 14 '22 00:10

Marcel Bro