本文介绍了更改复选框值而不触发 onCheckChanged的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我为我的 checkbox
有什么办法可以打电话
checkbox.setChecked(false);
不触发onCheckedChanged
推荐答案
不,你不能这样做.onCheckedChanged
方法直接从 setChecked
调用.您可以执行以下操作:
No, you can't do it. The onCheckedChanged
method is called directly from setChecked
. What you can do is the following:
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;
}
}
这篇关于更改复选框值而不触发 onCheckChanged的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!