我已经setOnCheckedChangeListener为我的checkbox
setOnCheckedChangeListener
checkbox
有没有办法我可以打电话
checkbox.setChecked(false);
在不触发onCheckedChanged
onCheckedChanged
不,你不能这样做。该onCheckedChanged方法直接从 调用setChecked。您可以执行以下操作:
setChecked
mCheck.setOnCheckedChangeListener (null); mCheck.setChecked (false); mCheck.setOnCheckedChangeListener (mListener);
查看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; } }