8
A
回答
7
下面是做到這一點的方式:
上的XML佈局文件每個RadioButton
創建一個單獨的RadioGroup
。例如:現在
<RadioGroup
android:id="@+id/rdoFooWrapper"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/rdoFoo"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RadioGroup>
<RadioGroup
android:id="@+id/rdoBooWrapper"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/rdoBoo"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RadioGroup>
,Java源代碼中,做這樣的事情:
rdoFooWrapper = (RadioGroup) findViewById(R.id.rdoFooWrapper);
rdoFoo = (RadioButton) findViewById(R.id.rdoFoo);
rdoBooWrapper = (RadioGroup) findViewById(R.id.rdoBooWrapper);
rdoBoo = (RadioButton) findViewById(R.id.rdoBoo);
rdoFoo.setOnCheckedChangeListener(this); // implement OnCheckedChangeListener to the current class
rdoBoo.setOnCheckedChangeListener(this);
// ...
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
rdoFooWrapper.clearCheck();
rdoBooWrapper.clearCheck();
}