Reputation: 111
I have a TableLayout and I'm adding rows dynamically. And in every row, I have a checkbox also.
My problem is controlling which checkboxes are checked and I don't know even how can I loop for each row. Please help me.
Upvotes: 1
Views: 1277
Reputation: 3005
Checkbox checkbox;
checkbox = (CheckBox) findViewById(R.id.checkbox);
checkBox.setChecked(false);
or true. that should work, just replace checkbox with your variable and @+id
EDIT:
You can implement OnCheckedChangeListener, then use something like
@Override
public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
// TODO Auto-generated method stub
switch (arg0.getId()) {
case R.id.checkbox1:
if (checkbox1.isChecked()){
//code to use when user checks the box
}else{
//code to use when user UNchecks the box
}
break;
}
}
Upvotes: 1