문제

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.

도움이 되었습니까?

해결책

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>

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top