【发布时间】:2021-11-30 07:31:44
【问题描述】:
在下面的代码中,我希望仅在单击复选框时才调用 afterscan 方法。但是有些我注意到一旦选中该方法,就会从所有其他复选框中调用该方法。任何帮助将不胜感激
Chk_class 类实现 CompoundButton.OnCheckedChangeListener{
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
result=new StringBuilder();
if(checkBox2.isChecked())
{
result.append("Connection issue |");
}
if(checkBox4.isChecked())
{
result.append("Machnical issue |");
}
Toast toast = Toast.makeText(getApplicationContext(), result.toString(), Toast.LENGTH_SHORT);
toast.setGravity(Gravity.TOP, 0, 0);
toast.show();
liftError=result.toString();
if(checkBoxer.isChecked()){
afterscan(); // this method is called from all other checkbox as well
}
}
}
【问题讨论】:
-
也许检查
buttonView是否为checkBoxer(如果所有复选框都使用相同的侦听器)