Preface
This chapter translates Android. widget. datepicker into Android 2.2 R1 and the date selector. More friends are welcome to join the Chinese translation operation of Android Api! My mailbox over140@gmail.com.
Statement
You are welcome to repost, but please keep the original source of the article :)
Blog: http://www.cnblogs.com
Farmer's uncle: http://www.cnblogs.com/over140/
Body
I. Structure
Public class datepicker extends framelayout
Java. Lang. Object
Android. View. View
Android. View. viewgroup
Android. widget. framelayout
Android. widget. datepicker
Ii. Overview
A calendar Layout View that selects year, month, and day. For the calendar view of the dialog box style, seeDatePickerDialog
.
Iii. Public Methods
Public int getdayofmonth ()
Obtain the number of days selected
Public int getmonth ()
Obtain the selected month. (Note: The returned value is 0 .. 11, which must be displayed with + 1)
Public int getyear ()
Obtain the selected year
Public void Init (INT year, int monthofyear, int dayofmonth, datepicker. ondatechangedlistener)
Initialization status. (Translator's note: Initialize year, month, and day)
Parameters
Year's first yearNew Date ()+ 1900 is required during the year of initialization, as shown below:Date. getyear() + 1900)
Monthofyear initial month.
The first day of dayofmonth.
The event listener that is notified when the ondatechangedlistener date is changed. It can be null ).
Public void setenabled (Boolean enabled)
Set the view activation status. The activation status varies with the subclass.
Parameters
If enabled is set to true, the view is started. If enabled is set to true, the view is disabled.
Public void updatedate (INT year, int monthofyear, int dayofmonth)
Update date
Iv. Protected Methods
Protected void dispatchrestoreinstancestate (sparsearray <parcelable> container)
Rewriting enables us to have full control over the storage or restoration of This widget. (Note: the parent class'sViewgroup. dispatchthawselfonlyMethod)
Parameters
The container sparsearray holds the previously saved state. The sparsearray which holds previusly saved state.
Protected void onrestoreinstancestate (parcelable state)
Allows the view to be re-applied. Previously, onsaveinstancestate () was used to generate an internal state. This function never calls an empty state.
Parameters
State the frozen state that had previusly been returned by onsaveinstancestate ().
Returns the status saved by calling onsaveinstancestate.
Protected parcelable onsaveinstancestate ()
Allows the view to generate an internal status, which can be used to create a new instance with the same status. This status should only contain information that is not persistent or cannot be rebuilt in the future. For example, you will never store your current location on the screen, because it will re-calculate and place a new instance at the view level.
You can store some examples here: the current cursor position in a text box (but usually not the text itself, the text is usually stored in the content provider) or other persistent storage), the current selected item in a list view.
Return Value
Returns a parcelable object that contains the current state of the view, or returns NULL if no State is saved. By default, null is returned.
5. Supplement
5.1 if you only want to display the year, month, and day, you can use the Android: layout_marginleft attribute to control the display of a part of the hidden control.
5.2 if date is used for initialization, pay attention to the Year issue:
Date = new date ();
Dpdate. INIT (date. getyear () + 1900, date. getmonth (), 1, null );
Code Description: dpdate is the datepicker control.
5.3 related articles
Datepicker Problems
Datepicker and timepicker)
Dynamic Input Date and Time in Android-datepicker and timepicker applications
End
To save time, we will not provide PDF or word downloads from this chapter. We will release a regular CHM collection for you to download. In addition, the article may be updated at any time. Please maintain the link.