I want to create a array of checkboxes so it can be easy to access them through a for loop. Something like this
for(int i = 0; i<10, i++)
{
checkbox[i].visibility(view.GONE);
}
But I am not sure if there is a way to create a array like this
>Solution :
Yes, it’s possible to create an array of Checkboxes. In below example i have created a fixed array of 10 Checkboxes.
// Create an array of CheckBoxes
CheckBox[] checkBoxes = new CheckBox[10];
// Initialize the CheckBoxes and add them to the parent layout
for (int i = 0; i < checkBoxes.length; i++) {
checkBoxes[i] = new CheckBox(context);
checkBoxes[i].setId(i);
// Also add checkbox to parent layout
}
// Access the CheckBoxes using a for loop
for (int i = 0; i < checkBoxes.length; i++) {
checkBoxes[i].setVisibility(View.GONE);
}