コード例 #1
0
    private void setItem(MenuItem item) {
      item.setChecked(itemChecked)
          .setVisible(itemVisible)
          .setEnabled(itemEnabled)
          .setCheckable(itemCheckable >= 1)
          .setTitleCondensed(itemTitleCondensed)
          .setIcon(itemIconResId)
          .setAlphabeticShortcut(itemAlphabeticShortcut)
          .setNumericShortcut(itemNumericShortcut);

      if (itemShowAsAction >= 0) {
        item.setShowAsAction(itemShowAsAction);
      }

      if (itemListenerMethodName != null) {
        if (mContext.isRestricted()) {
          throw new IllegalStateException(
              "The android:onClick attribute cannot " + "be used within a restricted context");
        }
        item.setOnMenuItemClickListener(
            new InflatedOnMenuItemClickListener(mRealOwner, itemListenerMethodName));
      }

      if (itemCheckable >= 2) {
        if (item instanceof MenuItemImpl) {
          MenuItemImpl impl = (MenuItemImpl) item;
          impl.setExclusiveCheckable(true);
        } else {
          menu.setGroupCheckable(groupId, true, true);
        }
      }

      boolean actionViewSpecified = false;
      if (itemActionViewClassName != null) {
        View actionView =
            (View)
                newInstance(
                    itemActionViewClassName,
                    ACTION_VIEW_CONSTRUCTOR_SIGNATURE,
                    mActionViewConstructorArguments);
        item.setActionView(actionView);
        actionViewSpecified = true;
      }
      if (itemActionViewLayout > 0) {
        if (!actionViewSpecified) {
          item.setActionView(itemActionViewLayout);
          actionViewSpecified = true;
        } else {
          Log.w(
              LOG_TAG,
              "Ignoring attribute 'itemActionViewLayout'." + " Action view already specified.");
        }
      }
      if (itemActionProvider != null) {
        item.setActionProvider(itemActionProvider);
      }
    }
コード例 #2
0
  public void setGroupCheckable(int group, boolean checkable, boolean exclusive) {
    final int N = mItems.size();

    for (int i = 0; i < N; i++) {
      MenuItemImpl item = mItems.get(i);
      if (item.getGroupId() == group) {
        item.setExclusiveCheckable(exclusive);
        item.setCheckable(checkable);
      }
    }
  }