@Override
  public void setCheckable(boolean checkable) {
    if (!checkable && mRadioButton == null && mCheckBox == null) {
      return;
    }

    // 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()) {
      if (mRadioButton == null) {
        insertRadioButton();
      }
      compoundButton = mRadioButton;
      otherCompoundButton = mCheckBox;
    } else {
      if (mCheckBox == null) {
        insertCheckBox();
      }
      compoundButton = mCheckBox;
      otherCompoundButton = mRadioButton;
    }

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

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

      // Make sure the other compound button isn't visible
      if (otherCompoundButton != null && otherCompoundButton.getVisibility() != View.GONE) {
        otherCompoundButton.setVisibility(View.GONE);
      }
    } else {
      if (mCheckBox != null) {
        mCheckBox.setVisibility(View.GONE);
      }
      if (mRadioButton != null) {
        mRadioButton.setVisibility(View.GONE);
      }
    }
  }
Beispiel #2
0
 /**
  * 处理复选框
  *
  * @param compoundButton
  * @param t
  */
 public void handleCompoundButton(CompoundButton compoundButton, T t) {
   compoundButton.setChecked(t.isChecked());
   compoundButton.setVisibility(isEnabledCheckMode() ? View.VISIBLE : View.GONE);
 }