android – 更改复选框值,不触发onCheckChanged

我有setOnCheckedChangeListener实现了我的复选框

有没有办法我可以打电话

checkbox.setChecked(false);

而不触发onCheckedChanged

不,你不能做。 onCheckedChanged方法直接从setChecked调用。您可以执行以下操作:

mCheck.setOnCheckedChangeListener (null);
mCheck.setChecked (false);
mCheck.setOnCheckedChangeListener (mListener);

看到source of CheckBox,并实现了setChecked:

public void  setChecked(boolean checked) {
    if (mChecked != checked) {
        mChecked = checked;
        refreshDrawableState();

        // Avoid infinite recursions if setChecked() is called from a listener
        if (mBroadcasting) {
            return;
        }

        mBroadcasting = true;
        if (mOnCheckedChangeListener != null) {
            mOnCheckedChangeListener.onCheckedChanged(this, mChecked);
        }

        if (mOnCheckedChangeWidgetListener != null) {
            mOnCheckedChangeWidgetListener.onCheckedChanged(this, mChecked);
        }

        mBroadcasting = false;            
    }
}
http://stackoverflow.com/questions/15523157/change-checkbox-value-without-triggering-oncheckchanged

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:android – 更改复选框值,不触发onCheckChanged