Familiar with ANDROIDAPI series 3--radiogroup and Raiobutton

Source: Internet
Author: User

Select a, A,c is selected at the same time

Select B, A,c is selected at the same time

<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "vertical" >        <RadiogroupAndroid:id= "@+id/radiogrp1"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"android:orientation= "Horizontal">                <RadioButtonAndroid:id= "@+id/aid"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "A"/>        <RadioButtonAndroid:id= "@+id/bid"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "B"/>        </Radiogroup><RadiogroupAndroid:id= "@+id/radiogrp2"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"android:orientation= "Horizontal" >        <RadioButtonAndroid:id= "@+id/cid"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "C" />        <RadioButtonAndroid:id= "@+id/did"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "D" />    </Radiogroup>    </LinearLayout>
 PackageCom.njulya.testradiobutton;Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.view.Menu;ImportAndroid.widget.RadioButton;ImportAndroid.widget.RadioGroup;ImportAndroid.widget.RadioGroup.OnCheckedChangeListener; Public classMainactivityextendsActivity {PrivateRadiogroup RADIOGRP1; PrivateRadiogroup RadioGrp2; PrivateRadioButton Abutton; PrivateRadioButton BButton; PrivateRadioButton CButton; PrivateRadioButton Dbutton; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);                Setcontentview (r.layout.activity_1); RADIOGRP1=(Radiogroup) Findviewbyid (R.ID.RADIOGRP1); RadioGrp2=(Radiogroup) Findviewbyid (R.ID.RADIOGRP2); Abutton=(RadioButton) Findviewbyid (R.id.aid); BButton=(RadioButton) Findviewbyid (r.id.bid); CButton=(RadioButton) Findviewbyid (R.ID.CID); Dbutton=(RadioButton) Findviewbyid (R.id.did); Radiogrouplistener Rgrplistener=NewRadiogrouplistener ();        Radiogrp1.setoncheckedchangelistener (Rgrplistener);            Radiogrp2.setoncheckedchangelistener (Rgrplistener); }    //import Android.widget.RadioGroup.OnCheckedChangeListener;    Private classRadiogrouplistenerImplementsoncheckedchangelistener{@Override Public voidOnCheckedChanged (Radiogroup radiogrp,intCheckedid) {            if(Checkedid = =Abutton.getid ()) {cbutton.setchecked (true); }Else if(Checkedid = =Bbutton.getid ()) {dbutton.setchecked (true); }Else if(Checkedid = =Cbutton.getid ()) {abutton.setchecked (true); }Else if(Checkedid = =Dbutton.getid ()) {bbutton.setchecked (true); } }} @Override Public BooleanOncreateoptionsmenu (Menu menu) {//inflate the menu; This adds items to the action bar if it is present.getmenuinflater (). Inflate (R.menu.main, menu); return true; }    }

Familiar with ANDROIDAPI series 3--radiogroup and Raiobutton

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.