How to add an item to a group in a submenu

Frank

At runtime I would like to add an item inside this group (in my options menu):

<item
        android:id="@+id/action_module_selector"
        android:alphabeticShortcut="m"
        android:orderInCategory="30"
        android:title="@string/module_selector_menu_title"
        app:showAsAction="never">

        <menu>
            <group
                android:id="@+id/group_modules"
                android:checkableBehavior="single">

                <!-- Modules should be added here at runtime -->

            </group>
        </menu>
    </item>

If I call subMenu.add(R.id.group_modules, moduleId, 1, title); they end up at the same level as the group, not inside the group, although I use R.id.group_modules. I would like to know how I can add them inside the group.

Frank

I "solved" it by removing the group, setting the sumbMenu's items to checkable and manually making sure only one of them is selected.

subMenu.findItem(id).setCheckable(true);

and on changes:

private void updateSelectedModuleOnMenu(Menu menu, int selectedPosition) {

    MenuItem menuItem = menu.findItem(R.id.action_module_selector);
    SubMenu subMenu = menuItem.getSubMenu();

    for (int i = 0; i < subMenu.size(); i++) {
        MenuItem item = subMenu.getItem(i);
        item.setChecked(i == selectedPosition);
    }
}

A solution using a group I could not find.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

how to display all menu and submenu item in a different drop down list?

分類Dev

How to join group item of Linq Query Group By?

分類Dev

Submenu item isn't clickable

分類Dev

How to add Badges on UIBarbutton item?

分類Dev

How to add an item to the top of a ListBox

分類Dev

QML: how to hide submenu?

分類Dev

How to select item in group list in selenium webdriver

分類Dev

How to add OnClick event on main menu (=Category, via TAction submenu) on ActionMainMenuBar?

分類Dev

SQL: How to display the same item by group and the same group of the dates

分類Dev

Hovering a textbox in a Menu/submenu item closes the item in the latest Chrome version

分類Dev

WordPressのadd_submenu_page

分類Dev

add class to parent li when submenu is active

分類Dev

How to add a single item to an existing spinner?

分類Dev

How to init List of tuple and add item in scala

分類Dev

How to add action to a Navigation Drawer item?

分類Dev

How to add an item to an array of array list

分類Dev

How to add item in DataGrid (smart way)

分類Dev

How to add Label on Bar Button Item?

分類Dev

How to add array items in one single item?

分類Dev

How to add a custom menu item to quickly add a custom tag

分類Dev

How to add async validation in FormBuilder.group?

分類Dev

How add group of objects to database with incremented id?

分類Dev

Change wrap of TMENU when active menu item has a submenu

分類Dev

Bootstrap Dropdown - Onclick menu items, scorll to last submenu item

分類Dev

how to get first item from a group and prepare Data class object

分類Dev

How to access a div target to toggle styling for a list group item in react?

分類Dev

How do you get an integer number for an item in group in SQL?

分類Dev

how to resize the dropdown submenu when the browser resizes

分類Dev

how to move dropdown-submenu to the top

Related 関連記事

  1. 1

    how to display all menu and submenu item in a different drop down list?

  2. 2

    How to join group item of Linq Query Group By?

  3. 3

    Submenu item isn't clickable

  4. 4

    How to add Badges on UIBarbutton item?

  5. 5

    How to add an item to the top of a ListBox

  6. 6

    QML: how to hide submenu?

  7. 7

    How to select item in group list in selenium webdriver

  8. 8

    How to add OnClick event on main menu (=Category, via TAction submenu) on ActionMainMenuBar?

  9. 9

    SQL: How to display the same item by group and the same group of the dates

  10. 10

    Hovering a textbox in a Menu/submenu item closes the item in the latest Chrome version

  11. 11

    WordPressのadd_submenu_page

  12. 12

    add class to parent li when submenu is active

  13. 13

    How to add a single item to an existing spinner?

  14. 14

    How to init List of tuple and add item in scala

  15. 15

    How to add action to a Navigation Drawer item?

  16. 16

    How to add an item to an array of array list

  17. 17

    How to add item in DataGrid (smart way)

  18. 18

    How to add Label on Bar Button Item?

  19. 19

    How to add array items in one single item?

  20. 20

    How to add a custom menu item to quickly add a custom tag

  21. 21

    How to add async validation in FormBuilder.group?

  22. 22

    How add group of objects to database with incremented id?

  23. 23

    Change wrap of TMENU when active menu item has a submenu

  24. 24

    Bootstrap Dropdown - Onclick menu items, scorll to last submenu item

  25. 25

    how to get first item from a group and prepare Data class object

  26. 26

    How to access a div target to toggle styling for a list group item in react?

  27. 27

    How do you get an integer number for an item in group in SQL?

  28. 28

    how to resize the dropdown submenu when the browser resizes

  29. 29

    how to move dropdown-submenu to the top

ホットタグ

アーカイブ