has not introduced to everybody to introduce the radio button (Radiogroup) the use, first shows the effect chart for everybody:
XML file
<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 "
tools:context= ". Mainactivity "
android:orientation=" vertical >
<textview
android:id= "@+id/txt"
android: Layout_width= "Fill_parent"
android:layout_height= "wrap_content"
android:text= "your sex for"/>
< Radiogroup
android:id= "@+id/sex"
android:layout_width= fill_parent "android:layout_height=" Wrap
_content ">
<radiobutton
android:id=" @+id/male "android:text=
" male "
/> <radiobutton
android:id= "@+id/female"
android:text= "female"/>
</RadioGroup>
Java files
public class Mainactivity extends activity {private TextView txt=null;
Private Radiogroup Sex=null;
Private RadioButton Male=null;
Private RadioButton Female=null;
@Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
this.txt= (TextView) Super.findviewbyid (r.id.txt);
this.sex= (Radiogroup) Super.findviewbyid (r.id.sex);
This.male= (RadioButton) Super.findviewbyid (R.id.male);
This.female= (RadioButton) Super.findviewbyid (R.id.female);
This.sex.setOnCheckedChangeListener (New Oncheckedchangelistenerimp ()); Private class Oncheckedchangelistenerimp implements oncheckedchangelistener{public void oncheckedchanged (Radiogroup
Group, int checkedid) {String temp=null;
if (MainActivity.this.male.getId () ==checkedid) {temp= "male";
else if (MainActivity.this.female.getId () ==checkedid) {temp= "female";
} MainActivity.this.txt.setText ("Your gender is" +temp); } }
The above is a small set to introduce the Android program development in the radio button (Radiogroup) The use of detailed, I hope to help you!