これを に入れonCreate
、ID を調整すると、次のようになります。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RadioGroup groupOne = (RadioGroup) findViewById(R.id.radio_group_one);
groupOne.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int index) {
RadioGroup groupTwo = (RadioGroup) findViewById(R.id.radio_group_two);
for(int i = 0; i < groupTwo.getChildCount(); i++) {
groupTwo.getChildAt(i).setEnabled(true);
}
}
});
}
そして、XML レイアウト ファイルは次のようになります。
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radio_group_one">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Group 1 button 1"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Group 1 button 2"/>
</RadioGroup>
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radio_group_two">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Group 2 button 1"
android:enabled="false"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Group 2 button 2"
android:enabled="false"/>
</RadioGroup>
したがって、2 番目のボタンはRadioGroup
最初は無効になっており、ユーザーが最初のボタンを選択した後にのみ有効になります。