public int findItemIndex(int id) { final int size = size(); for (int i = 0; i < size; i++) { MenuItemImpl item = mItems.get(i); if (item.getItemId() == id) { return i; } } return -1; }
public MenuItem findItem(int id) { final int size = size(); for (int i = 0; i < size; i++) { MenuItemImpl item = mItems.get(i); if (item.getItemId() == id) { return item; } else if (item.hasSubMenu()) { MenuItem possibleItem = item.getSubMenu().findItem(id); if (possibleItem != null) { return possibleItem; } } } return null; }
public boolean bindNativeOverflow( android.view.Menu menu, android.view.MenuItem.OnMenuItemClickListener listener, HashMap<android.view.MenuItem, MenuItemImpl> map) { final List<MenuItemImpl> nonActionItems = getNonActionItems(); if (nonActionItems == null || nonActionItems.size() == 0) { return false; } boolean visible = false; menu.clear(); for (MenuItemImpl nonActionItem : nonActionItems) { if (!nonActionItem.isVisible()) { continue; } visible = true; android.view.MenuItem nativeItem; if (nonActionItem.hasSubMenu()) { android.view.SubMenu nativeSub = menu.addSubMenu( nonActionItem.getGroupId(), nonActionItem.getItemId(), nonActionItem.getOrder(), nonActionItem.getTitle()); SubMenuBuilder subMenu = (SubMenuBuilder) nonActionItem.getSubMenu(); for (MenuItemImpl subItem : subMenu.getVisibleItems()) { android.view.MenuItem nativeSubItem = nativeSub.add( subItem.getGroupId(), subItem.getItemId(), subItem.getOrder(), subItem.getTitle()); nativeSubItem.setIcon(subItem.getIcon()); nativeSubItem.setOnMenuItemClickListener(listener); nativeSubItem.setEnabled(subItem.isEnabled()); nativeSubItem.setIntent(subItem.getIntent()); nativeSubItem.setNumericShortcut(subItem.getNumericShortcut()); nativeSubItem.setAlphabeticShortcut(subItem.getAlphabeticShortcut()); nativeSubItem.setTitleCondensed(subItem.getTitleCondensed()); nativeSubItem.setCheckable(subItem.isCheckable()); nativeSubItem.setChecked(subItem.isChecked()); if (subItem.isExclusiveCheckable()) { nativeSub.setGroupCheckable(subItem.getGroupId(), true, true); } map.put(nativeSubItem, subItem); } nativeItem = nativeSub.getItem(); } else { nativeItem = menu.add( nonActionItem.getGroupId(), nonActionItem.getItemId(), nonActionItem.getOrder(), nonActionItem.getTitle()); } nativeItem.setIcon(nonActionItem.getIcon()); nativeItem.setOnMenuItemClickListener(listener); nativeItem.setEnabled(nonActionItem.isEnabled()); nativeItem.setIntent(nonActionItem.getIntent()); nativeItem.setNumericShortcut(nonActionItem.getNumericShortcut()); nativeItem.setAlphabeticShortcut(nonActionItem.getAlphabeticShortcut()); nativeItem.setTitleCondensed(nonActionItem.getTitleCondensed()); nativeItem.setCheckable(nonActionItem.isCheckable()); nativeItem.setChecked(nonActionItem.isChecked()); if (nonActionItem.isExclusiveCheckable()) { menu.setGroupCheckable(nonActionItem.getGroupId(), true, true); } map.put(nativeItem, nonActionItem); } return visible; }