0

I recently had a problem with menu items, and asked a question here - Group menu items work but don't display checkmark.

I figured out the problem; however, I noticed a strange behavior with single-selection radio button menu items.

I know you have to set the checked state of a selectable menu item

Menu items in the Icon Menu (from the options menu) cannot display a checkbox or radio button. If you choose to make items in the Icon Menu checkable, you must manually indicate the checked state by swapping the icon and/or text each time the state changes.

However, it does not matter if you set it to true or false. Both provide a radio button-like check state that you would expect.

Example

    switch (item.getItemId()) {

        case R.id.mode_sign :
            item.setChecked(true);
            display = BinaryOperation.Display.SIGN;
            return true;

        case R.id.mode_verb :
            item.setChecked(true);
            display = BinaryOperation.Display.VERB;
            return true;

        case R.id.mode_noun :
            item.setChecked(true);
            display = BinaryOperation.Display.NOUN;
            return true;

        default : return super.onOptionsItemSelected(item);
    }

The above code has the exact same behavior if you swap the item.setChecked(true) to item.setChecked(false). As expected, if you remove the setChecked() statements, then no menu item will be selected.

So how does the process of menu item selection actually work? And why does setting true or false not matter?

Community
  • 1
  • 1
Christopher Rucinski
  • 4,737
  • 2
  • 27
  • 58

0 Answers0