Пример #1
0
  void setExclusiveItemChecked(MenuItem item) {
    final int group = item.getGroupId();

    final int N = mItems.size();
    for (int i = 0; i < N; i++) {
      MenuItemImpl curItem = mItems.get(i);
      if (curItem.getGroupId() == group) {
        if (!curItem.isExclusiveCheckable()) continue;
        if (!curItem.isCheckable()) continue;

        // Check the item meant to be checked, uncheck the others (that are in the group)
        curItem.setCheckedInt(curItem == item);
      }
    }
  }
Пример #2
0
  public void setChecked(boolean checked) {
    CompoundButton compoundButton;

    if (mItemData.isExclusiveCheckable()) {
      if (mRadioButton == null) {
        insertRadioButton();
      }
      compoundButton = mRadioButton;
    } else {
      if (mCheckBox == null) {
        insertCheckBox();
      }
      compoundButton = mCheckBox;
    }

    compoundButton.setChecked(checked);
  }
Пример #3
0
  public void setCheckable(boolean checkable) {

    if (!checkable && mRadioButton == null && mCheckBox == null) {
      return;
    }

    if (mRadioButton == null) {
      insertRadioButton();
    }
    if (mCheckBox == null) {
      insertCheckBox();
    }

    // Depending on whether its exclusive check or not, the checkbox or
    // radio button will be the one in use (and the other will be otherCompoundButton)
    final CompoundButton compoundButton;
    final CompoundButton otherCompoundButton;

    if (mItemData.isExclusiveCheckable()) {
      compoundButton = mRadioButton;
      otherCompoundButton = mCheckBox;
    } else {
      compoundButton = mCheckBox;
      otherCompoundButton = mRadioButton;
    }

    if (checkable) {
      compoundButton.setChecked(mItemData.isChecked());

      final int newVisibility = checkable ? VISIBLE : GONE;
      if (compoundButton.getVisibility() != newVisibility) {
        compoundButton.setVisibility(newVisibility);
      }

      // Make sure the other compound button isn't visible
      if (otherCompoundButton.getVisibility() != GONE) {
        otherCompoundButton.setVisibility(GONE);
      }
    } else {
      mCheckBox.setVisibility(GONE);
      mRadioButton.setVisibility(GONE);
    }
  }