android.view.MenuItem.getGroupId()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(10.7k)|赞(0)|评价(0)|浏览(88)

本文整理了Java中android.view.MenuItem.getGroupId()方法的一些代码示例,展示了MenuItem.getGroupId()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MenuItem.getGroupId()方法的具体详情如下:
包路径:android.view.MenuItem
类名称:MenuItem
方法名:getGroupId

暂无

代码示例

代码示例来源:origin: stackoverflow.com

public void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo) {
  menu.add(UNIQUE_FRAGMENT_GROUP_ID, MENU_OPTION_1, 0, R.string.src1);
  menu.add(UNIQUE_FRAGMENT_GROUP_ID, MENU_OPTION_2, 0, R.string.src2);
}
public boolean onContextItemSelected(MenuItem item) {
  //only this fragment's context menus have group ID of -1
  if (item.getGroupId() == UNIQUE_FRAGMENT_GROUP_ID) {
    switch(item.getItemId()) {
    case MENU_OPTION_1: doSomething(); break;
    case MENU_OPTION_2: doSomethingElse(); break;
  }
}

代码示例来源:origin: hidroh/materialistic

@Override
public boolean onOptionsItemSelected(MenuItem item) {
  if (item.getGroupId() == R.id.menu_sort_group) {
    item.setChecked(true);
    sort(item.getItemId() == R.id.menu_sort_recent);
    return true;
  }
  return super.onOptionsItemSelected(item);
}

代码示例来源:origin: square/assertj-android

public MenuItemAssert hasGroupId(int id) {
 isNotNull();
 int actualId = actual.getGroupId();
 assertThat(actualId) //
   .overridingErrorMessage("Expected group ID <%s> but was <%s>.", id, actualId) //
   .isEqualTo(id);
 return this;
}

代码示例来源:origin: rey5137/material

/**
 * This function should be called in onPrepareOptionsMenu(Menu) of Activity that use
 * Toolbar as ActionBar, or after inflating menu.
 */
public void onPrepareMenu(){
  if(mGroupChanged || mMenuDataChanged){
    mToolbar.getViewTreeObserver().addOnGlobalLayoutListener(mOnGlobalLayoutListener);
    Menu menu = mToolbar.getMenu();
    for(int i = 0, count = menu.size(); i < count; i++){
      MenuItem item = menu.getItem(i);
      item.setVisible(item.getGroupId() == mCurrentGroup || item.getGroupId() == 0);
    }
    mMenuDataChanged = false;
  }
}

代码示例来源:origin: TeamNewPipe/NewPipe

/**
 * Called when an item of the quality selector or the playback speed selector is selected
 */
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
  if (DEBUG)
    Log.d(TAG, "onMenuItemClick() called with: menuItem = [" + menuItem + "], menuItem.getItemId = [" + menuItem.getItemId() + "]");
  if (qualityPopupMenuGroupId == menuItem.getGroupId()) {
    final int menuItemIndex = menuItem.getItemId();
    if (selectedStreamIndex == menuItemIndex ||
        availableStreams == null || availableStreams.size() <= menuItemIndex) return true;
    final String newResolution = availableStreams.get(menuItemIndex).resolution;
    setRecovery();
    setPlaybackQuality(newResolution);
    reload();
    qualityTextView.setText(menuItem.getTitle());
    return true;
  } else if (playbackSpeedPopupMenuGroupId == menuItem.getGroupId()) {
    int speedIndex = menuItem.getItemId();
    float speed = PLAYBACK_SPEEDS[speedIndex];
    setPlaybackSpeed(speed);
    playbackSpeedTextView.setText(formatSpeed(speed));
  }
  return false;
}

代码示例来源:origin: ZieIony/Carbon

private void setMenuInternal(Menu menu) {
  this.menu = menu;
  RowListAdapter<Serializable> adapter = new RowListAdapter<>(MenuItem.class, NavigationRow::new);
  adapter.addFactory(PaddingItem.class, PaddingRow::new);
  adapter.addFactory(DividerItem.class, DividerRow::new);
  setAdapter(adapter);
  ArrayList<Serializable> items = new ArrayList<>();
  items.addAll(menu.getVisibleItems());
  for (int i = 0; i < items.size() - 1; i++) {
    if (((android.view.MenuItem) items.get(i)).getGroupId() != ((android.view.MenuItem) items.get(i + 1)).getGroupId())
      items.add(++i, new DividerItem());
  }
  items.add(0, new PaddingItem(getResources().getDimensionPixelSize(R.dimen.carbon_paddingHalf)));
  items.add(new PaddingItem(getResources().getDimensionPixelSize(R.dimen.carbon_paddingHalf)));
  if (header != null) {
    items.add(new CustomHeaderItem());
    adapter.addFactory(CustomHeaderItem.class, parent -> new CustomHeaderRow(header));
  }
  ((RowListAdapter<Serializable>) getAdapter()).setItems(items);
}

代码示例来源:origin: ZieIony/Carbon

private void updateRecycler() {
    if (menu == null)
      return;

    recycler.setLayoutManager(style == Style.List ? new LinearLayoutManager(getContext()) : new GridLayoutManager(getContext(), 3));

    ArrayList<Serializable> items = new ArrayList<>();
    items.addAll(menu.getVisibleItems());
    if (style == Style.List) {
      for (int i = 0; i < items.size() - 1; i++) {
        if (((android.view.MenuItem) items.get(i)).getGroupId() != ((android.view.MenuItem) items.get(i + 1)).getGroupId())
          items.add(++i, new DividerItem());
      }
      items.add(new PaddingItem(getResources().getDimensionPixelSize(R.dimen.carbon_paddingHalf)));
    }

    RowListAdapter<Serializable> adapter = new RowListAdapter<>(MenuItem.class, style == Style.List ? BottomSheetRow::new : BottomSheetCell::new);
    adapter.addFactory(PaddingItem.class, PaddingRow::new);
    adapter.addFactory(DividerItem.class, DividerRow::new);
    adapter.setItems(items);

    recycler.setAdapter(adapter);
  }
}

代码示例来源:origin: ZieIony/Carbon

public static Menu getMenu(Context context, android.view.Menu baseMenu) {
  Context contextWrapper = CarbonContextWrapper.wrap(context);
  Menu menu = new Menu(contextWrapper);
  for (int i = 0; i < baseMenu.size(); i++) {
    android.view.MenuItem menuItem = baseMenu.getItem(i);
    menu.add(menuItem.getGroupId(), menuItem.getItemId(), menuItem.getOrder(), menuItem.getTitle()).setIcon(menuItem.getIcon()).setVisible(menuItem.isVisible()).setEnabled(menuItem.isEnabled());
  }
  return menu;
}

代码示例来源:origin: TeamNewPipe/NewPipe

private boolean drawerItemSelected(MenuItem item) {
  switch (item.getGroupId()) {
    case R.id.menu_services_group:
      changeService(item);
      break;
    case R.id.menu_tabs_group:
      try {
        tabSelected(item);
      } catch (Exception e) {
        ErrorActivity.reportUiError(this, e);
      }
      break;
    case R.id.menu_options_about_group:
      optionsAboutSelected(item);
      break;
    default:
      return false;
  }
  drawer.closeDrawers();
  return true;
}

代码示例来源:origin: Flipboard/bottomsheet

int groupId = item.getGroupId();
if (groupId != currentGroupId && menuType == LIST) {
  items.add(SheetMenuItem.SEPARATOR);

代码示例来源:origin: mikepenz/MaterialDrawer

MenuItem mMenuItem = mMenu.getItem(i);
IDrawerItem iDrawerItem;
if (!subMenu && mMenuItem.getGroupId() != groupId && mMenuItem.getGroupId() != 0) {
  groupId = mMenuItem.getGroupId();
  iDrawerItem = new DividerDrawerItem();
  getItemAdapter().add(iDrawerItem);
  getItemAdapter().add(iDrawerItem);
  addMenuItems(mMenuItem.getSubMenu(), true);
} else if (mMenuItem.getGroupId() != 0 || subMenu) {
  iDrawerItem = new SecondaryDrawerItem()
      .withName(mMenuItem.getTitle().toString())

代码示例来源:origin: Neamar/KISS

public boolean onMenuItemClick(MenuItem item) {
    switch (item.getGroupId()) {
      case EXCLUDE_HISTORY_ID:
        excludeFromHistory(context, appPojo, parent);
        return true;
      case EXCLUDE_KISS_ID:
        // remove item since it will be hidden
        parent.removeResult(AppResult.this);
        excludeFromKiss(context, appPojo);
        return true;
    }
    return true;
  }
});

代码示例来源:origin: chrisk44/Hijacker

public boolean onMenuItemClick(android.view.MenuItem item){
    switch(item.getGroupId()){
      case TYPE_AP:
        //ap
        onTargetSelected(AP.APs.get(item.getItemId()));
        break;
      case TYPE_ST:
        //st
        onTargetSelected(ST.STs.get(item.getItemId()));
        break;
    }
    return true;
  }
});

代码示例来源:origin: stackoverflow.com

if(item.getGroupId() == mNumber){
  Log.d("ViewPagerContextMenuBug", "onContextItemSelected called for number " + mNumber);
  Toast.makeText(getActivity(), "onContextItemSelected called for number " + mNumber, Toast.LENGTH_SHORT).show();

代码示例来源:origin: chrisk44/Hijacker

public boolean onMenuItemClick(android.view.MenuItem item){
    if(item.getGroupId()==-1){
      //Open actions manager
      FragmentTransaction ft = mFragmentManager.beginTransaction();
      ft.replace(R.id.fragment1, new CustomActionManagerFragment());
      ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
      ft.addToBackStack(null);
      ft.commitAllowingStateLoss();
    }else{
      onActionSelected(cmds.get(item.getItemId()));
    }
    return true;
  }
});

代码示例来源:origin: willowtreeapps/Hyperion-Android

public static Collection<ViewAttribute> createMenuAttributes(@NonNull Context context, @NonNull Menu menu) {
  final Resources res = context.getResources();
  List<ViewAttribute> attributes = new ArrayList<>();
  attributes.add(new ViewAttribute<>("MenuSize", menu.size()));
  attributes.add(new ViewAttribute<>("MenuHasVisibleItems", menu.hasVisibleItems()));
  for (int i = 0; i < menu.size(); i++) {
    MenuItem item = menu.getItem(i);
    String prefix = "Item " + i + ": ";
    attributes.add(new ViewAttribute<>(prefix + "Title", item.getTitle()));
    attributes.add(new ViewAttribute<>(prefix + "ContentDescription",
        MenuItemCompat.getContentDescription(item)));
    attributes.add(new ViewAttribute<>(prefix + "TooltipText", MenuItemCompat.getTooltipText(item)));
    attributes.add(new ViewAttribute<>(prefix + "Checkable", item.isCheckable()));
    attributes.add(new ViewAttribute<>(prefix + "Checked", item.isChecked()));
    attributes.add(new ViewAttribute<>(prefix + "Enabled", item.isEnabled()));
    attributes.add(new ViewAttribute<>(prefix + "Visible", item.isVisible()));
    attributes.add(new ViewAttribute<>(prefix + "Order", item.getOrder()));
    attributes.add(new ViewAttribute<Void>(prefix + "Icon", item.getIcon()));
    attributes.add(createColorAttribute("IconTint",
        MenuItemCompat.getIconTintList(item)));
    attributes.add(new ViewAttribute<>("IconTintMode",
        new PorterDuffModeValue(MenuItemCompat.getIconTintMode(item))));
    attributes.add(new ViewAttribute<>(prefix + "Id", new ResourceValue(res, item.getItemId())));
    attributes.add(new ViewAttribute<>(prefix + "GroupId", new ResourceValue(res, item.getGroupId())));
  }
  return attributes;
}

代码示例来源:origin: chrisk44/Hijacker

public boolean onMenuItemClick(android.view.MenuItem item) {
  if(item.getGroupId()==0){
    custom_mac=null;
    AP temp = AP.APs.get(item.getItemId());

代码示例来源:origin: stackoverflow.com

public boolean onNavigationItemSelected(final MenuItem menuItem) {

  //if an item from extras group is clicked,refresh NAV_ITEMS_MAIN to remove previously checked item
  if (menuItem.getGroupId() == NAV_ITEMS_EXTRA) {

    navigationView.getMenu().setGroupCheckable(NAV_ITEMS_MAIN, false, true);
    navigationView.getMenu().setGroupCheckable(NAV_ITEMS_EXTRA, true, true);
    }else{

    navigationView.getMenu().setGroupCheckable(NAV_ITEMS_MAIN, true, true);
    navigationView.getMenu().setGroupCheckable(NAV_ITEMS_EXTRA, false, true);

  }
  //Update highlighted item in the navigation menu
  menuItem.setChecked(true);
}

代码示例来源:origin: vanilla-music/vanilla

@Override
public boolean onContextItemSelected(MenuItem item)
{
  int group = item.getGroupId();
  int id = item.getItemId();
  if (group == CTX_MENU_GRP_SHUFFLE)
    setState(PlaybackService.get(this).setShuffleMode(id));
  else if (group == CTX_MENU_GRP_FINISH)
    setState(PlaybackService.get(this).setFinishAction(id));
  return true;
}

代码示例来源:origin: VREMSoftwareDevelopment/WiFiAnalyzer

@Override
  public void execute(NavigationMenu navigationMenu) {
    MenuItem actual = menu.getItem(navigationMenu.ordinal());
    assertEquals(navigationGroup.ordinal(), actual.getGroupId());
    assertEquals(mainActivity.getResources().getString(navigationMenu.getTitle()), actual.getTitle());
    assertEquals(navigationMenu.ordinal(), actual.getItemId());
    assertEquals(navigationMenu.ordinal(), actual.getOrder());
  }
}

相关文章