I have created check boxes programmatically.
Here is my code:
llmain = (LinearLayout) findViewById(R.id.linearLayoutMain);
lLayout = new LinearLayout[b];
for (int j = 0; j < b; j++) {
int x = 0;
x = x + (j * 5);
lLayout[j] = new LinearLayout(CheckBoxdemo.this);
lLayout[j].setLayoutParams(new LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
lLayout[j].setOrientation(LinearLayout.VERTICAL);
llmain.addView(lLayout[j]);
for (int i = x; i < x + 5; i++) {
if (x > a) {
break;
} else {
if (testArrayList.contains(idsplit[i])) {
cb = new CheckBox(CheckBoxdemo.this);
cb.setText(namesplit[i]);
cb.setId(i + 1);
cb.setChecked(true);
cb.setTextColor(Color.BLACK);
cb.setTextSize(12f);
cb.setButtonDrawable(R.drawable.checkbox);
cb.setPadding(35, 5, 25, 5);
cb.setTag(i + 1);
cb.setOnCheckedChangeListener(handleCheck(cb));
if ((count1.equals(1)) || (count1.equals(2))) {
cb.setEnabled(true);
} else {
cb.setEnabled(false);
}
lLayout[j].addView(cb);
} else {
cb = new CheckBox(CheckBoxdemo.this);
cb.setText(namesplit[i]);
cb.setId(i + 1);
cb.setTextColor(Color.BLACK);
cb.setTextSize(12f);
cb.setButtonDrawable(R.drawable.checkbox);
cb.setPadding(35, 5, 25, 5);
cb.setTag(i + 1);
cb.setOnCheckedChangeListener(handleCheck(cb));
if ((count1.equals(1)) || (count1.equals(2))) {
cb.setEnabled(true);
} else {
cb.setEnabled(false);
}
lLayout[j].addView(cb);
}
}
}
}
- Now I have received value of 15 check boxes from the database.
Now, all the check boxes are non- selected. If I click on any 5 of them; then I want to get the value of these 5- selected check boxes all together in an array, on just a click of a button.
How can I implement this???????
