I have a checkbox that can be dynamically disabled and tied to a click listener:
CheckBox chkbox = (CheckBox)findViewById(R.id.chkboxid);
if(condition) {
chkbox.setEnabled(false);
chkbox.setOnClickListener(displayPopup);
} else {
chkbox.setOnClickListener(handleToggle);
}
The purpose of this is if the checkbox is disabled, I want to give users that click on the checkbox more info about why the option is disabled for them.
I have since realized that disabled widgets do not send click events to click listeners. I have since tried setting the LinearLayout
it exists in as clickable by doing the following:
CheckBox chkbox = (CheckBox)findViewById(R.id.checkboxName);
LinearLayout layout = (LinearLayout)findViewById(R.id.layoutName);
if(condition) {
chkbox.setEnabled(false);
layout.setClickable(true);
layout.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
layout.setOnClickListener(displayPopup);
} else {
chkbox.setOnClickListener(handleToggle);
}
This works for clicking anywhere inside the LinearLayout
except on the disabled checkbox. It is not following the FOCUS_BLOCK_DESCENDANTS
setting. I have also tried placing an invisible clickable object over the checkbox but was not successful there either. Any ideas?
EDIT: We're stuck in API lvl 8 right now, or otherwise I'd try lowering the alpha of the checkbox instead of disabling it to at least simulate the appearance of being disabled.