<?xml version= "1.0" encoding= "Utf-8"? ><manifest xmlns:android= "Http://schemas.android.com/apk/res/android" Package= "Com.hanqi.test5" > <Application Android:allowbackup= "true"Android:icon= "@mipmap/ic_launcher"Android:label= "@string/app_name"Android:supportsrtl= "true"Android:theme= "@style/apptheme" > <activity android:name= ". UIActivity1 "> <intent-filter> <action android:name=" Android.intent.action.MAIN "/> ; <category android:name= "Android.intent.category.LAUNCHER"/> </intent-filter> </activity& Gt <activity android:name= ". Longclickactivityactivity "> <intent-filter> <action android:name=" android.intent.act Ion. MAIN "/> <category android:name=" Android.intent.category.LAUNCHER "/> </intent-filte r> </activity> <activity android:name= ". Calculatoractivity "> <intent-filter> <action android:name=" Android.intent.action.MAI N "/> <category android:name=" Android.intent.category.LAUNCHER "/> </INTENT-FILTER&G T </activity> <activity android:name= ". Mainactivity "&Gt <intent-filter> <action android:name= "Android.intent.action.MAIN"/> <categor Y android:name= "Android.intent.category.LAUNCHER"/> </intent-filter> </activity> <activity android:name= ". Activity1 "/> </application></manifest>
PackageCom.hanqi.test5;ImportAndroid.os.Bundle;Importandroid.support.annotation.IdRes;Importandroid.support.v7.app.AppCompatActivity;ImportAndroid.widget.CheckBox;ImportAndroid.widget.CompoundButton;ImportAndroid.widget.RadioButton;ImportAndroid.widget.RadioGroup;ImportAndroid.widget.Toast; Public classUIActivity1extendsappcompatactivity {@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 ()); } 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"? ><linearlayout 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"android:orientation= "Vertical"Tools:context= "Com.hanqi.test5.UIActivity1" > <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"/></linearlayout>
When the virtual Machine version 6.0 is implemented, the self-animating effect is good and can be used for surveys or exams
:
Android Course---radio box and check box