<?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:orientation= "Vertical"android:padding= "10DP"Tools:context= "Com.example.dell.test5.UiActivity1" > <TextView android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Please select Android's development language"/> <Radiogroup android:layout_width= "Wrap_content"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"/> <RadioButton android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "C"Android:id= "@+id/rb2"Android:layout_marginright= "30DP"android:checked= "true"/> <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"/> <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>
PackageCom.example.dell.test5;ImportAndroid.os.Bundle;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); Radiogroup Radiogroup=(Radiogroup) Findviewbyid (R.ID.RG); Radiogroup.setoncheckedchangelistener (NewRadiogroup.oncheckedchangelistener () {@Override Public voidOnCheckedChanged (Radiogroup Group,intCheckedid) { if(Checkedid = =r.id.rb3) {toast.maketext (UiActivity1. This, "the right choice.", Toast.length_short). Show (); } RadioButton RB=(RadioButton) Findviewbyid (Checkedid); Toast.maketext (UiActivity1. This, Rb.gettext (), Toast.length_long). Show (); } }); CheckBox Cb_st=(CheckBox) Findviewbyid (R.id.cb_st); Cb_st.setoncheckedchangelistener (NewCboncheckedchangelistenner ()); CheckBox CB_JC=(CheckBox) Findviewbyid (R.ID.CB_JC); Cb_jc.setoncheckedchangelistener (NewCboncheckedchangelistenner ()); CheckBox Cb_xt=(CheckBox) Findviewbyid (R.ID.CB_XT); Cb_xt.setoncheckedchangelistener (NewCboncheckedchangelistenner ()); CheckBox Cb_xhx=(CheckBox) Findviewbyid (R.ID.CB_XHX); Cb_xhx.setoncheckedchangelistener (NewCboncheckedchangelistenner ()); } Private classCboncheckedchangelistennerImplementsCompoundbutton.oncheckedchangelistener {@Override Public voidOnCheckedChanged (Compoundbutton Buttonview,BooleanisChecked) {CheckBox CB=(CheckBox) Buttonview; if(isChecked) {toast.maketext (UiActivity1. This, "checked" +Cb.gettext (), Toast.length_short). Show (); } Else{toast.maketext (UiActivity1). This, "Canceled" +Cb.gettext (), Toast.length_short). Show (); } } }}
Android Radio box and check box (practice)