Exemplo n.º 1
0
  /**
   * Invokes the item by calling various listeners or callbacks.
   *
   * @return true if the invocation was handled, false otherwise
   */
  public boolean invoke() {
    if (mClickListener != null && mClickListener.onMenuItemClick(this)) {
      return true;
    }

    if (mMenu.dispatchMenuItemSelected(mMenu.getRootMenu(), this)) {
      return true;
    }

    if (mItemCallback != null) {
      mItemCallback.run();
      return true;
    }

    if (mIntent != null) {
      try {
        mMenu.getContext().startActivity(mIntent);
        return true;
      } catch (ActivityNotFoundException e) {
        Log.e(TAG, "Can't find activity to handle intent; ignoring", e);
      }
    }

    if (mActionProvider != null && mActionProvider.onPerformDefaultAction()) {
      return true;
    }

    return false;
  }
Exemplo n.º 2
0
 public MenuItem setActionView(int resId) {
   final Context context = mMenu.getContext();
   final LayoutInflater inflater = LayoutInflater.from(context);
   setActionView(inflater.inflate(resId, new LinearLayout(context), false));
   return this;
 }
Exemplo n.º 3
0
 public MenuItem setTitle(int title) {
   return setTitle(mMenu.getContext().getString(title));
 }