Java 在动态创建的复选框中选中
我在运行时动态创建了一些复选框,现在我想知道其中一个是否被选中。我怎么能做到Java 在动态创建的复选框中选中,java,android,checkbox,Java,Android,Checkbox,我在运行时动态创建了一些复选框,现在我想知道其中一个是否被选中。我怎么能做到 for (int i = 0; i < cnt; i++) { cb = new CheckBox(getApplicationContext()); TextView txt = new TextView(getApplicationContext()); ll2 = new LinearLa
for (int i = 0; i < cnt; i++) {
cb = new CheckBox(getApplicationContext());
TextView txt = new TextView(getApplicationContext());
ll2 = new LinearLayout(
PollActivity.this);
ll2.setOrientation(LinearLayout.HORIZONTAL);
ll2.addView(cb);
ll.addView(ll2);
}
for(int i=0;i
您需要设置为复选框,以便在单击复选框时触发事件。例如:
cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
// do your code here
}
});
我建议您为每个复选框设置(在循环中)
现在您可以处理每个复选框的事件。只需检查返回布尔值的cb.isChecked()。给我们一些代码。需要看看它是如何创建的,但它不工作,你能给我一个完整的例子吗?我一天不能做这个,请帮帮我
cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
// do some action
}
}
});