If you put this into your onCreate
, adjusting for your IDs:
@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);
}
}
});
}
And then your XML layout file should look something like this:
<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>
So the buttons in the second RadioGroup
are disabled at first, and only becomes enabled after the user makes a selection in the first one.