My xml code is:
<group android:checkableBehavior="single">
<item android:id="@+id/group_1_box_1"/>
<item android:id="@+id/group_1_box_2"/>
</group>
<group android:checkableBehavior="single">
<item android:id="@+id/group_2_box_1"/>
<item android:id="@+id/group_2_box_2"/>
</group>
The problem I am having is that when I change the state of group_1_box_1 to true, it not only sets group_1_box_2 to false, it also sets the group_2 boxes to false.
Edit: Here's my code
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.group_1_box_1:
item.setChecked(true);
return true;
case R.id.group_1_box_2:
item.setChecked(true);
return true;
case R.id.group_2_box_1:
item.setChecked(true);
return true;
case R.id.group_2_box_2:
item.setChecked(true);
return true;
default:
return super.onOptionsItemSelected(item);
}
You just need to add unique IDs to each of the group
items in the xml file.
<group
android:id="@+id/menuGroup_1" <!-- Here -->
android:checkableBehavior="single">
<item android:id="@+id/group_1_box_1"/>
<item android:id="@+id/group_1_box_2"/>
</group>
<group
android:id="@+id/menuGroup_2" <!-- And here -->
android:checkableBehavior="single">
<item android:id="@+id/group_2_box_1"/>
<item android:id="@+id/group_2_box_2"/>
</group>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With