Android Radio box and check box (practice)

Source: Internet
Author: User

<?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)

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.