Reputation: 9216
I created some checkboxed dynamically in runtime, now i want to know ehen one of them ckecked or not. how i can do this?
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);
}
Upvotes: 0
Views: 95
Reputation: 33505
I suggest you to set(in loop) for each CheckBox
set OnCheckedChangeListener.
cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
// do some action
}
}
});
Now you are able to handle events for each CheckBox.
Upvotes: 1
Reputation: 132982
you will need to set CompoundButton.OnCheckedChangeListener for CheckBox to fire an event when checkbox clicked. Example :
cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
// do your code here
}
});
Upvotes: 1