//ActivityRadioGroup.java
package android.ActivityUI;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioGroup;
public class ActivityRadioGroup extends Activity implements View.OnClickListener{
RadioGroup mRadioGroup;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.radiogroup);
mRadioGroup = (RadioGroup)findViewById(R.id.radio_group);
Button radiogroup_clear = (Button)findViewById(R.id.radiogroup_clear);
radiogroup_clear.setOnClickListener(this);
}
public void onClick(View v){
mRadioGroup.clearCheck();
}
}
//radiogroup.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RadioGroup
android:orientation="vertical"
android:id="@+id/radio_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checkedButton="@+id/lunch">
<RadioButton
android:id="@+id/breakfast"
android:text="breakdfast"
/>
<RadioButton
android:id="@+id/lunch"
android:text="lunch"
/>
<RadioButton
android:id="@+id/dinner"
android:text="dinner"
/>
<RadioButton
android:id="@+id/all"
android:text="all"
/>
</RadioGroup>
<Button
android:id="@+id/radiogroup_clear"
android:text="clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
点击clear按钮: