Question

I require that sometimes my Checkboxes in a ListView are not tickable. I'm using setEnabled(false).

Is there anyway to fire a toast message when the user still clicks on the disabled Checkbox?

I am also using a custom ArrayAdapter overriding the getView method.

Was it helpful?

Solution

You can :) using a helper class that extends CheckBox and overrides onTouchEvent, kind of like:

public class DisabledTouchableCheckbox extends CheckBox {

    public DisabledTouchableCheckBox(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if ((!isEnabled()) && (event.getAction()==MotionEvent.ACTION_DOWN)) 
            showToast();
        return super.onTouchEvent(event);
    }

    private void showToast() {
            ... show your toast
    }

}

Then in your XML's you have to change <CheckBox> for <com.YOURPACKAGE.DisabledTouchableCheckBox>

OTHER TIPS

You can't. There's a reason they call it disabled.

You could create a custom Checkbox using the same assets, but I guess that's just wasting time. User's will know the checkbox is disabled, because disabled widgets are shown in 30% alpha.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top