Android Dynamic Checkbox Issue
I am in the process of trying to add dynamic checkbox to my activity. However being a beginner i cant get round the basics of being able to add checkboxes and remove them. Here is
Solution 1:
You need to store the references to those checkboxes somewhere, but not reusing the same variable.
CheckBox[] cbs = new CheckBox[5];
for(int i=0; i<5; i++){
cbs[i] = new CheckBox(this);
ll.addView(cb);
cbs.setText("Test");
}
ll.addView(submit);
submit.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
for(int i = 0; i < 5; i++) {
ll.removeView(cbs[i]);
}
ll.removeView(submit);
Questions();
}});
Post a Comment for "Android Dynamic Checkbox Issue"