Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: Disabled checkbox not responding to click events
    primarykey
    data
    text
    <p>I have a checkbox that can be dynamically disabled and tied to a click listener:</p> <pre><code>CheckBox chkbox = (CheckBox)findViewById(R.id.chkboxid); if(condition) { chkbox.setEnabled(false); chkbox.setOnClickListener(displayPopup); } else { chkbox.setOnClickListener(handleToggle); } </code></pre> <p>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.</p> <p>I have since realized that disabled widgets do not send click events to click listeners. I have since tried setting the <code>LinearLayout</code> it exists in as clickable by doing the following:</p> <pre><code>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); } </code></pre> <p>This works for clicking anywhere inside the <code>LinearLayout</code> except on the disabled checkbox. It is not following the <code>FOCUS_BLOCK_DESCENDANTS</code> setting. I have also tried placing an invisible clickable object over the checkbox but was not successful there either. Any ideas? </p> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload