How to create a submenu with radio buttons in Android?
Set the checkableBehavior in xml to single.Here is some code:
<menu> <group android:id="@+id/group" android:checkableBehavior="single"> <item android:id="@+id/menu_sort_by_name" android:title="@string/action_sort_by_name"/> <item android:id="@+id/menu_sort_by_last_edit" android:title="@string/action_sort_by_last_edit"/> </group></menu>
I found out that groups of menus and submenus are processed separately, that is a group formed in a submenu, should be addressed via the submenu, not via the top-level menu. So the solution is to call:
sub.setGroupCheckable(1, true, true);
This code works as expected, that is items in the submenu show radiobuttons instead of checkboxes.