Calendar Date Time Picker

Source: Internet
Author: User

1. Calendar

1 <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"2 android:orientation= "vertical"3 Android:layout_width= "Match_parent"4 Android:layout_height= "Match_parent">5 6 <CalendarView7         Android:layout_width= "Wrap_content"8 Android:layout_height= "Wrap_content"9 Android:firstdayofweek= "2"Ten android:maxdate= "12/31/2016" One android:mindate= "01/01/2016" A Android:id= "@+id/cv_1" - Android:background= "#999" - android:visibility= "Gone"> the     </CalendarView> -  - </LinearLayout>

2. Date picker

1 <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"2 android:orientation= "vertical"3 Android:layout_width= "Match_parent"4 Android:layout_height= "Match_parent">5 6 <DatePicker7         Android:layout_width= "Match_parent"8 Android:layout_height= "Match_parent"9 android:maxdate= "12/31/2023"Ten android:mindate= "01/01/2000" One Android:calendarviewshown= "false" A Android:id= "@+id/dp_1" - android:visibility= "Gone" -         > the     </DatePicker> -  - </LinearLayout>

3. Time Picker

1 <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"2 android:orientation= "vertical"3 Android:layout_width= "Match_parent"4 Android:layout_height= "Match_parent">5 6 <Timepicker7         Android:layout_width= "Wrap_content"8 Android:layout_height= "Wrap_content"9 Android:id= "@+id/tp_1"Ten         > One     </Timepicker> A </LinearLayout>

4. Code Pilot commands

1  Packagecom.example.administrator.testapp2;2 3 ImportAndroid.os.Bundle;4 Importandroid.support.v7.app.AppCompatActivity;5 ImportAndroid.widget.CalendarView;6 ImportAndroid.widget.DatePicker;7 ImportAndroid.widget.TimePicker;8 ImportAndroid.widget.Toast;9 Ten /** One * Created by Administrator on 2016/05/07. A  */ -  Public classTestActivity2extendsappcompatactivity{ -  the CalendarView cv_1; - DatePicker dp_1; - Timepicker tp_1; -  + @Override -     protected voidonCreate (Bundle savedinstancestate) { +         Super. OnCreate (savedinstancestate); A Setcontentview (r.layout.activity_test2); at  -Cv_1 =(CalendarView) Findviewbyid (r.id.cv_1); -  -Cv_1.setondatechangelistener (NewCalendarview.ondatechangelistener () { - @Override -              Public voidOnselecteddaychange (CalendarView view,intYearintMonthintdayofmonth) { in  -Toast.maketext (TestActivity2. This, "The selected date is:" +year+ "-" +month+ "-" +DayOfMonth, Toast.length_short). Show (); to             } +         }); -  theDp_1 =(DatePicker) Findviewbyid (r.id.dp_1); *  $Dp_1.init (2015,0,1,NewDatepicker.ondatechangedlistener () {Panax Notoginseng  - @Override the              Public voidOndatechanged (DatePicker view,intYearintMonthofyear,intdayofmonth) { +  AToast.maketext (TestActivity2. This, "The selected date is:" +year+ "-" + (monthofyear+1) + "-" +DayOfMonth, Toast.length_short). Show (); the             } +         }); -  $Tp_1 =(Timepicker) Findviewbyid (r.id.tp_1); $  -Tp_1.setis24hourview (true); -  theTp_1.setontimechangedlistener (NewTimepicker.ontimechangedlistener () { - @OverrideWuyi              Public voidOntimechanged (Timepicker view,intHourofday,intminute) { the  -Toast.maketext (TestActivity2. This, "The selected time is:" +hourofday+ ":" +minute, Toast.length_short). Show (); Wu             } -         }); About     } $  -  -  -}

5. Run the Code directory

1 <?XML version= "1.0" encoding= "Utf-8"?>2 <Manifestxmlns:android= "Http://schemas.android.com/apk/res/android"3  Package= "Com.example.administrator.testapp2">4 5     <Application6         Android:allowbackup= "true"7 Android:icon= "@mipmap/ic_launcher"8 Android:label= "@string/app_name"9 Android:supportsrtl= "true"Ten Android:theme= "@style/apptheme"> One         <ActivityAndroid:name=". TestActivity2 "> A             <Intent-filter> -             <ActionAndroid:name= "Android.intent.action.MAIN" /> -             <categoryAndroid:name= "Android.intent.category.LAUNCHER" /> the         </Intent-filter> -         </Activity> -  -     </Application> +  - </Manifest>

Calendar Date Time Picker

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.