<1> Introduction
A calendar Layout View with year, month, and day selected
<2> class inheritance
Java. Lang. Object
Android. View. View
Android. View. viewgroup
Android. widget. framelayout
Android. widget. datepicker
<3> Method
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.
Ondatechangedlistener
Event listening that notifies the user when the date changes. 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
Example:
Package android. test; import android. app. activity; import android. OS. bundle; import android. widget. datepicker; import android. widget. toast; public class testactivity extends activity {/** called when the activity is first created. */private datepicker = NULL; @ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); datepicker = (datepicker) findviewbyid (R. id. datepicker); string date = "year:" + datepicker. getyear () + "month:" + datepicker. getmonth () + "day:" + datepicker. getdayofmonth (); toast. maketext (testactivity. this, date, toast. length_short ). show ();}}
<? XML version = "1.0" encoding = "UTF-8"?> <Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" Android: Orientation = "vertical"> <textview Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: text = "datepicker"/> <datepicker Android: Id = "@ + ID/datepicker" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content"/> </linearlayout>