As Android phones get more and more hot, the Android OS is also popular with developers, and many programmers are slowly switching to Android development. Today, the Wheat Academy's Android development teacher told everyone about Android Radio basic applications, and today we followed the Wheat Academy Android teacher to learn how the Android radio box was implemented.
When using the Android radio box, use Radiogroup to group
When you select the Radiogroup in the box, the Radiogroup check is called () method
When the Append radio box is selected for processing,
1. Call the Setoncheckedchangelistener () method and pass the Radiogroup.oncheckedchangelistener instance as a parameter
2. In Radiogroup.oncheckedchangelistener's OnCheckedChanged () method, obtain an instance of the selected Android radio box
Example Routines Code (JAVA)
1. View Sourceprint?01.radiogroup Radiogroup = (radiogroup)
2. Findviewbyid (Id.radiogroup);
3. Radiogroup.check (Id.radiobuttongreen);
4. Radiobuttonradiobutton = (RadioButton) Findviewbyid (
5. Radiogroup.getcheckedradiobuttonid ());
6. LOG.V ("Test", String.valueof (Radiobutton.gettext ()));
7. Radiogroup.setoncheckedchangelistener (
8. Newradiogroup.oncheckedchangelistener () {
9. Public Voidoncheckedchanged (
10.RadioGroupgroup,
11.int Checkedid) {
12.RadioButtonradioButton = (RadioButton) Findviewbyid (Checkedid);
13.LOG.V ("Test", String.valueof (Radiobutton.gettext ()));
14.}
15.});
Example Routines Code (RESOURCE)
1. < radiogroupandroid:id= "@+id/radiogroup"
2. Android:layout_width= "Wrap_content"
3. android:layout_height= "Wrap_content" >
4. < radiobuttonandroid:id= "@+id/radiobuttonred"
5. Android:layout_width= "Wrap_content"
6. android:layout_height= "Wrap_content"
7. android:text= "@string/red"/>
8. < radiobuttonandroid:id= "@+id/radiobuttongreen"
9. Android:layout_width= "Wrap_content"
10.android:layout_height= "Wrap_content"
11.android:text= "@string/green"/>
12.< radiobuttonandroid:id= "@+id/radiobuttonblue"
13.android:layout_width= "Wrap_content"
14.android:layout_height= "Wrap_content"
15.android:text= "@string/blue"/>
</radiogroup>
For Android Development tutorials, go to:Http://www.maiziedu.com/course/android/
Basic application of the single box for Android development entry