Android Control Radiogroup and RadioButton (radio control)

Source: Internet
Author: User

First, Radiogroup and RadioButton

1. What is Radiogroup:

A collection of RadioButton that provides a multi-select mechanism

2. What is RadioButton:

RadioButton wrapped in Radiogroup, Radiogroup represents a group of RadioButton, the following can have a lot of RadioButton, but only one is selected

3. Radiogroup Properties:

android:orientation--set the form of RadioButton in Radiogroup (with two values: horizontal (horizontal arrangement) and vertical (vertical arrangement))

Second, the code shows:

<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"android:orientation= "Horizontal" >    <RadiogroupAndroid:id= "@+id/radiogroup1"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:orientation= "Horizontal" >        <RadioButtonAndroid:id= "@+id/radio0"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:checked= "true"Android:text= "Male" />        <RadioButtonAndroid:id= "@+id/radio1"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "female" />    </Radiogroup></LinearLayout>
 PackageCom.muke.textview_edittext;ImportAndroid.os.Bundle;ImportAndroid.widget.RadioGroup;ImportAndroid.widget.RadioGroup.OnCheckedChangeListener;Importandroid.app.Activity; Public classMainactivityextendsActivityImplementsoncheckedchangelistener{PrivateRadiogroup RG; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);                Setcontentview (R.layout.activity_main); //First step: Initialize the control (find the control you want to manipulate)RG =(Radiogroup) Findviewbyid (r.id.radiogroup1); //Step Two: Implement Radiogroup monitoring EventsRg.setoncheckedchangelistener ( This); } @Override Public voidOnCheckedChanged (Radiogroup Group,intCheckedid) {        //Checkedid indicates the ID of the radiobutton that was selected        Switch(checkedid) { CaseR.id.radio0:system.out.println ("Male is selected");  Break;  CaseR.id.radio1:system.out.println ("Female is selected");  Break; }    }        }

Android Control Radiogroup and RadioButton (radio control)

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.