Android Dynamic Checkbox
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 my code....
private void createCheckbox() {
for(int i=0; i<5; i++){
cb = new CheckBox(this);
ll.addView(cb);
cb.setText("Test");
}
ll.addView(submit);
submit.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
for(int i = 0; i < 5; i++) {
ll.removeView(cb);
}
ll.removeView(submit);
Questions();
}});
}
ll is a linerlayout object. The idea is when the code runs, 5 checkboxes appear and then once the user clicks on the submit button the开发者_JS百科y get removed. Currently the boxes are being seen, but when the submit button is pressed only one of the five is being removed. I don't understand what i am doing wrong?
For loop not ending correctly, curly bracket wrong place
精彩评论