1. Main.xml
<?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" > <DatePicker android:id= "@+id/datepicker1" android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" > </DatePicker></LinearLayout>
2. Firseacitivy.java
Public classFirstactivityextendsActivity {/**Called when the activity is first created.*/@Override Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.main); DatePicker Mydatepicker= (DatePicker) Findviewbyid (r.id.datepicker1);//Get ObjectOndatechangedlistener Ondatechangedlistener =NewDatepicker.ondatechangedlistener () {//Setting up Listeners@Override Public voidOndatechanged (DatePicker view,intYearintMonthofyear,intdayofmonth) { //TODO auto-generated Method StubToast.maketext (Getapplicationcontext (), "Current date:" +year+ "Year" + (monthofyear+1) + "month" +dayofmonth+ "Day", Toast.length_long) . Show ();//Show the date after the change } }; Mydatepicker.init (, 1, 1, ondatechangedlistener);//Initialize date selection control display month = Set month +1Mydatepicker.updatedate (2012, 11, 31);//Update Date }}
3.
Android--date control uses and displays the selected date