Android--radiogroup and checkboxes

Source: Internet
Author: User

Xml

<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutxmlns: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"Tools:context= "Com.example.chenshuai.test322.UIActivity">    <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Please select what is the Android development language?" "android:padding= "10DP"/>    <Radiogroup Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"android:orientation= "Horizontal"Android:id= "@+id/rg">        <RadioButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "C + +"Android:id= "@+id/rb1"Android:layout_marginright= "30DP"android:checked= "true"            />        <RadioButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "C"Android:id= "@+id/rb2"Android:layout_marginright= "30DP"            />        <RadioButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "JAVA"Android:id= "@+id/rb3"Android:layout_marginright= "30DP"            />        <RadioButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "C #"Android:id= "@+id/rb4"            />    </radiogroup>     <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Please select font effect:"Android:id= "@+id/ziti"/>    <CheckBoxAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Song Body"android:checked= "true"Android:id= "@+id/cb_song"/>    <CheckBoxAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Bold"Android:id= "@+id/cb_cu"/>    <CheckBoxAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Italic"Android:id= "@+id/cb_xie"/>    <CheckBoxAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Underline"Android:id= "@+id/cb_xia"/></LinearLayout>

Java

 Packagecom.example.chenshuai.test322;ImportAndroid.os.Bundle;Importandroid.support.v7.app.AppCompatActivity;ImportAndroid.widget.CheckBox;ImportAndroid.widget.CompoundButton;ImportAndroid.widget.RadioButton;ImportAndroid.widget.RadioGroup;ImportAndroid.widget.Toast; Public classUiactivityextendsappcompatactivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.LAYOUT.ACTIVITY_UI); Radiogroup Radiogroup=(Radiogroup) Findviewbyid (R.ID.RG); //Radiogroup Listener Event anonymous inner classRadiogroup.setoncheckedchangelistener (New Radiogroup.oncheckedchangelistener () {@Override Public voidOnCheckedChanged (radiogroup Group, int  Checkedid) {RadioButton RB=(RadioButton) Findviewbyid (Checkedid); if(Checkedid = =r.id.rb3) {toast.maketext (uiactivity. This, "the right choice.", Toast.length_long). Show (); } toast.maketext (uiactivity. This, Rb.gettext (), Toast.length_long). Show ();        }        }); CheckBox Cb_song=(CheckBox) Findviewbyid (R.id.cb_song); Cb_song.setoncheckedchangelistener (NewCboncheckedchangelistener ()); CheckBox CB_CU=(CheckBox) Findviewbyid (R.ID.CB_CU); Cb_cu.setoncheckedchangelistener (NewCboncheckedchangelistener ()); CheckBox Cb_xia=(CheckBox) Findviewbyid (R.id.cb_xia); Cb_xia.setoncheckedchangelistener (NewCboncheckedchangelistener ()); CheckBox Cb_xie=(CheckBox) Findviewbyid (R.id.cb_xie); Cb_xie.setoncheckedchangelistener (NewCboncheckedchangelistener ()); }        //Listener event Inner class for CheckBox    Private classCboncheckedchangelistenerImplements compoundbutton.oncheckedchangelistener {@Override Public voidOnCheckedChanged (Compoundbutton Buttonview,BooleanisChecked) {CheckBox CB=(CheckBox) Buttonview; if(isChecked) {toast.maketext (uiactivity. This, "checked" +Cb.gettext (), Toast.length_short). Show (); }            Else{toast.maketext (uiactivity). This, "uncheck" +Cb.gettext (), Toast.length_short). Show (); }        }    }}

Android--radiogroup and checkboxes

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.