Explore new DatePicker usage and explore datepicker
DatePicker is rarely used. DatePicker is required for the project. when the project is used, it finds some changes with the previous ones. Repeat the usage of DatePicker.
First:
First, the usage of xml files:
Previously, the android: spinnersShown and android: calendarViewShown attributes were used to control whether DatePicker displays the scroll selector, calendar, or both.
Now, if you only write these two attributes, DatePicker always displays only the calendar and does not display the scroll selector.
The android: datePickerMode = "spinner" attribute is used together with the preceding two attributes to perfectly control the display form of DatePicker.
Here is my xml file:
<DatePicker android:id="@+id/date_picker" android:layout_width="wrap_content" android:layout_height="wrap_content" android:calendarViewShown="false" android:spinnersShown="true" android:datePickerMode="spinner" android:layout_gravity="center_horizontal"></DatePicker>
View Code
The Java code is as follows:
DatePicker datePicker = (DatePicker) view. findViewById (R. id. date_picker); Calendar c = Calendar. getInstance (); int year = c. get (Calendar. YEAR); int month = c. get (Calendar. MONTH); int day = c. get (Calendar. DAY_OF_MONTH); // initialize the DatePicker component and specify the listener datePicker during initialization. init (year, month, day, new DatePicker. onDateChangedListener () {@ Override public void onDateChanged (DatePicker datePicker, int I, int i1, int i2 ){}});View Code
Note that when the system language is set to English, the format is month-day-year, and the system language is Chinese, and the format is year-month-day.
This is quite user-friendly. I would like to give a thumbs up to Google.
This basically satisfies my needs. I will study it later...