Android 在这种情况下,如何使复选框单击事件
我已经动态地做了一个Android 在这种情况下,如何使复选框单击事件,android,checkbox,Android,Checkbox,我已经动态地做了一个复选框,对于特定的情况,我想使用复选框。一旦选中更改 但它显示了一个错误,您可以在RadioGroup if(sQuestionId.toString()=="518" || "518".equals(sQuestionId.toString()){ llCheckBoxQuestion=new LinearLayout(this); llCheckBoxQuestion.setLayoutPa
复选框
,对于特定的情况,我想使用复选框。一旦选中更改
但它显示了一个错误,您可以在RadioGroup
if(sQuestionId.toString()=="518" || "518".equals(sQuestionId.toString()){
llCheckBoxQuestion=new LinearLayout(this);
llCheckBoxQuestion.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
llCheckBoxQuestion.setOrientation(android.widget.LinearLayout.HORIZONTAL);
cb=new CheckBox(this);
cb.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
cb.setId(idCheckBox2);
String sQuestion=ele.getText(0);
tvQuestion=new TextView(this);
tvQuestion.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
tvQuestion.setText(sQuestion.replace("nbsp;","").replace("&", "").replace(">", "").replace("<", "").replace("BR", "\n"));
// tvQuestion.setText(sQuestion.replace("&"," "));
tvQuestion.setTextColor(Color.WHITE);
tvQuestion.setTextSize(16);
tvQuestion.setGravity(Gravity.TOP);
llCheckBoxQuestion.addView(cb);
llCheckBoxQuestion.addView(tvQuestion);
ll.addView(tvTitle);
//ll.addView(tv);
ll.addView(llChild);
//ll.addView(tvQuestion);
ll.addView(llCheckBoxQuestion);
}
我已将此复选框用于已更改的事件
cb.setOnCheckedChangeListener(new OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton arg0,boolean arg1) {
if(arg0.isChecked()){
fnCheckChanged(t1.getText().toString(),t3.getText().toString(),arg1,arg0);
}
}
});
错误:
The method setOnCheckedChangeListener(CompoundButton.OnCheckedChangeListener) in the type CompoundButton is not applicable for the arguments (new RadioGroup.OnCheckedChangeListener(){})
如何解决此问题?在setOnCheckedChangeListener()中,您需要将匿名类作为CompoundButton传递。OnCheckedChangeListener()在第一种情况下,所有的“==”都是无用的。请删除它们以提高可读性(同时,我建议使用一组字符串和
contains
方法),这已经做得很好了,但是我如何才能使用我的选中的已更改的Listner,如问题所述类似于此,您的导入是错误的(但由于您不想发布它,这只是一个假设)