How to create a submenu with radio buttons in Android?

android, contextmenu

Solution

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.

Problem

I have a problem in a simple case (at least, it looks like so). I need to create a submenu for a context menu dynamically and provide each item with a radiobox. I made a lot of trials. When I call `menu.setGroupCheckable(0, true, true)`, where 0 is by default the menu itself, it displays radio buttons to the right on every menu item as expected, but I need this for submenu. So I have the following code: ``` SubMenu sub = menu.addSubMenu(R.string.name); int count = 1000; for(String e : someList) { MenuItem item = sub.add(1, count, count, e); count++; } menu.setGroupCheckable(1, true, true); ``` In this case I don't see neither radioboxes, nor checkboxes in the submenu. Then I wrote the following code: ``` SubMenu sub = menu.addSubMenu(R.string.name); int count = 1000; for(String e : someList) { MenuItem item = sub.add(1, count, count, e); item.setCheckable(true); count++; } menu.setGroupCheckable(1, true, true); ``` This makes the submenu to have a checkbox in every item, and the checkboxes work exclusively, but I want radioboxes, because they look more intuitively for exclusive selection. So, how can this be accomplished?

Original source