Android Course---Calendar selector and time picker

Source: Internet
Author: User
Tags gettext

 PackageCom.hanqi.test5;ImportAndroid.os.Bundle;Importandroid.support.annotation.IdRes;Importandroid.support.v7.app.AppCompatActivity;ImportAndroid.widget.CheckBox;ImportAndroid.widget.CompoundButton;ImportAndroid.widget.DatePicker;ImportAndroid.widget.ImageView;ImportAndroid.widget.RadioButton;ImportAndroid.widget.RadioGroup;ImportAndroid.widget.Switch;ImportAndroid.widget.TimePicker;ImportAndroid.widget.Toast;ImportAndroid.widget.ToggleButton; Public classUIActivity1extendsappcompatactivity {ImageView IV; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.LAYOUT.ACTIVITY_UI1); //Radio BoxRadiogroup Radiogroup =(Radiogroup) Findviewbyid (R.ID.RG); Radiogroup.setoncheckedchangelistener (NewRadiogroup.oncheckedchangelistener () { Public voidOnCheckedChanged (Radiogroup Group, @IdResintCheckedid) {                if(Checkedid = = R.ID.RB3)//Rb3 Set as the correct answer{toast.maketext (UIActivity1). This, "the right choice.", Toast.length_long). Show (); } RadioButton RB=(RadioButton) Findviewbyid (Checkedid); Toast.maketext (UIActivity1. This, Rb.gettext (), Toast.length_long). Show ();        }        }); //check boxCheckBox Cb_st =(CheckBox) Findviewbyid (R.id.cb_st); Cb_st.setoncheckedchangelistener (NewCboncheckedchanglistenter () {@Override Public voidOnCheckedChanged (Compoundbutton Buttonview,BooleanisChecked)        {            }        }); Cb_st.setoncheckedchangelistener (NewCboncheckedchanglistenter ()); CheckBox CB_JC=(CheckBox) Findviewbyid (R.ID.CB_JC); Cb_jc.setoncheckedchangelistener (NewCboncheckedchanglistenter ()); CheckBox Cb_xt=(CheckBox) Findviewbyid (R.ID.CB_XT); Cb_xt.setoncheckedchangelistener (NewCboncheckedchanglistenter ()); CheckBox Cb_xhx=(CheckBox) Findviewbyid (R.ID.CB_XHX); Cb_xhx.setoncheckedchangelistener (NewCboncheckedchanglistenter ()); IV=(ImageView) Findviewbyid (R.ID.IV); ToggleButton Tob=(ToggleButton) Findviewbyid (R.id.tob); Tob.setoncheckedchangelistener (NewToncheckedchangelistenter ()); Switch SW=(Switch) Findviewbyid (R.ID.SW); Sw.setoncheckedchangelistener (NewToncheckedchangelistenter ()); DatePicker dp_1=(DatePicker) Findviewbyid (r.id.dp_1); Dp_1.init (2000, 0, 1,NewDatepicker.ondatechangedlistener () {@Override Public voidOndatechanged (DatePicker view,intYearintMonthofyear,intdayofmonth) {Toast.maketext (UIActivity1). This, year+ "-" + (monthofyear+1) + "-" +dayofmonth,toast.length_short). Show ();        }        }); Timepicker tp_1=(Timepicker) Findviewbyid (r.id.tp_1); Tp_1.setontimechangedlistener (NewTimepicker.ontimechangedlistener () {@Override Public voidOntimechanged (Timepicker view,intHourofday,intminute) {Toast.maketext (UIActivity1). This, Hourofday + ":" +minute,toast.length_short). Show ();    }        }); }    Private classToncheckedchangelistenterImplementscompoundbutton.oncheckedchangelistener{ Public voidOnCheckedChanged (Compoundbutton Buttonview,BooleanisChecked) {            if(isChecked) {iv.setimageresource (r.drawable.on);//set up a picture source            }            Else{iv.setimageresource (R.drawable.off); }        }    }    Private classCboncheckedchanglistenterImplementsCompoundbutton.oncheckedchangelistener {@Override Public voidOnCheckedChanged (Compoundbutton Buttonview,BooleanisChecked) {CheckBox CB=(CheckBox) Buttonview; if(isChecked) {toast.maketext (UIActivity1. This, "checked" +Cb.gettext (), Toast.length_long). Show (); }        Else{toast.maketext (UIActivity1). This, "Canceled" +Cb.gettext (), Toast.length_long). Show (); }    }    }}
<?xml version= "1.0" encoding= "Utf-8"? ><scrollview xmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:padding= "10DP"Tools:context= "Com.hanqi.test5.UIActivity1"Android:scrollbars= "None" ><LinearLayout android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "Vertical" > <TextView android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Please select what is the Android development language?" "/> <Radiogroup android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"android:orientation= "Horizontal"Android:id= "@+id/rg" > <RadioButton android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "C + +"Android:id= "@+id/rb1"Android:layout_marginright= "30DP"android:checked= "true"/> <RadioButton android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "C"Android:id= "@+id/rb2"Android:layout_marginright= "30DP"/> <RadioButton android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "JAVA"Android:id= "@+id/rb3"Android:layout_marginright= "30DP"/> <RadioButton android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "C #"Android:id= "@+id/rb4"/> </RadioGroup> <TextView android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Please select font effect"/> <CheckBox android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Song Body"Android:id= "@+id/cb_st"android:checked= "true"/> <CheckBox android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Bold"Android:id= "@+id/cb_jc"/> <CheckBox android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Italic"Android:id= "@+id/cb_xt"/> <CheckBox android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Underline"Android:id= "@+id/cb_xhx"/> <ImageView android:layout_width= "80DP"Android:layout_height= "80DP"Android:background= "#f0f"Android:scaletype= "Centercrop"android:src= "@drawable/yuantu"Android:alpha= "0.3"Android:id= "@+id/iv1"/><!--alpha: Picture transparency, values between 0 and 1-<ImageView android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:src= "@drawable/off"Android:id= "@+id/iv"/> <ToggleButton android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:texton= "Open"Android:textoff= "Off"Android:id= "@+id/tob"/> <Switch android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Switch"Android:textoff= "Off"Android:texton= "Open"Android:id= "@+id/sw"/> <ToggleButton android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:texton=""Android:textoff=""Android:background= "@drawable/mybutton"Android:id= "@+id/tob1"/> <AnalogClock android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"/><!--dial Type-<DigitalClock android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"/><!--Digital-<DatePicker android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:startyear= "2000"Android:endyear= "2016"android:mindate= "1/1/2000"android:maxdate= "1/1/2016"Android:id= "@+id/dp_1"Android:calendarviewshown= "false" ></DatePicker> <!--date picker Calendarviewshown: Whether the calendar is displayed for version 4.0 only---<Timepicker android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:id= "@+id/tp_1" ></TimePicker><!--Time Picker--<CalendarView android:layout_width= "Match_parent"Android:layout_height= "Match_parent" ></CalendarView><!--calendar display--></linearlayout></scrollview>

Show:

Android Course---Calendar selector and 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.