public virtual void setCheckable(bool 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) android.widget.CompoundButton compoundButton; android.widget.CompoundButton otherCompoundButton; if (mItemData.isExclusiveCheckable()) { compoundButton = mRadioButton; otherCompoundButton = mCheckBox; } else { compoundButton = mCheckBox; otherCompoundButton = mRadioButton; } if (checkable) { compoundButton.setChecked(mItemData.isChecked()); 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); } }