1. Calendar
<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" Android:orientation = "vertical" Android:layout_width = "Match_parent" Span style= "color: #000000;" > Android:layout_height = "Match_parent" ><calendarview Android:layout_w Idth = "Wrap_content" Android:layout_height =" Wrap_content " Android:firstdayofweek = "2" Android:maxdate =" 12/31/2016 " Android:mindate = "01/01/2016" Android:id =" @+id/cv_1 " Android:background = "#999" android:visibility =" Gone "> < ;/calendarview></linearlayout>
View Code
2. Date picker
<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" android:orientation= " Vertical " android:layout_width=" Match_parent " android:layout_height=" Match_parent " ><DatePicker android:layout_width= "Match_parent" android:layout_height= "Match _parent " android:maxdate=" 12/31/2023 " android:mindate=" 01/01/2000 " Android:calendarviewshown= "false" android:id= "@+id/dp_1" android:visibility = "Gone" > </DatePicker></LinearLayout>
View Code
3. Time Picker
<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" android:orientation= " Vertical " android:layout_width=" Match_parent " android:layout_height=" Match_parent " ><timepicker android:layout_width= "Wrap_content" android:layout_height= "Wrap_ Content " android:id=" @+id/tp_1 " > </TimePicker></LinearLayout>
View Code
4. Code Pilot commands
Packagecom.example.administrator.testapp2;ImportAndroid.os.Bundle;Importandroid.support.v7.app.AppCompatActivity;ImportAndroid.widget.CalendarView;ImportAndroid.widget.DatePicker;ImportAndroid.widget.TimePicker;ImportAndroid.widget.Toast;/*** Created by Administrator on 2016/05/07.*/ Public classTestActivity2extendsappcompatactivity{CalendarView cv_1; DatePicker dp_1; Timepicker tp_1; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.LAYOUT.ACTIVITY_TEST2); Cv_1=(CalendarView) Findviewbyid (r.id.cv_1); Cv_1.setondatechangelistener (NewCalendarview.ondatechangelistener () {@Override Public voidOnselecteddaychange (CalendarView view,intYearintMonthintdayofmonth) {Toast.maketext (TestActivity2). This, "The selected date is:" +year+ "-" +month+ "-" +DayOfMonth, Toast.length_short). Show (); } }); Dp_1=(DatePicker) Findviewbyid (r.id.dp_1); Dp_1.init (2015,0,1,NewDatepicker.ondatechangedlistener () {@Override Public voidOndatechanged (DatePicker view,intYearintMonthofyear,intdayofmonth) {Toast.maketext (TestActivity2). This, "The selected date is:" +year+ "-" + (monthofyear+1) + "-" +DayOfMonth, Toast.length_short). Show (); } }); Tp_1=(Timepicker) Findviewbyid (r.id.tp_1); Tp_1.setis24hourview (true); Tp_1.setontimechangedlistener (NewTimepicker.ontimechangedlistener () {@Override Public voidOntimechanged (Timepicker view,intHourofday,intminute) {Toast.maketext (TestActivity2). This, "The selected time is:" +hourofday+ ":" +minute, Toast.length_short). Show (); } }); }}
View Code
5. Run the Code directory
<?xml version= "1.0" encoding= "Utf-8"? ><manifest xmlns:android= "http://schemas.android.com/apk/res/ Android "package =" Com.example.administrator.testapp2 "> <application android:allowbackup = "true" Android:icon = "@mipmap/ic _launcher " Android:label =" @string/app_name " Android:supportsrtl = "true" Android:theme =" @style/apptheme "> <activity android:name= ". TestActivity2 "> <intent-filter> <action android:name=" Android.intent.action.MAIN "/> <category android:name= "Android.intent.category.LAUNCHER"/> </intent-filter> </ac Tivity> </application></manifest>
View Code
Calendar Date Time Picker