I have sixteen image buttons, so I am creating an array of image buttons. I would like to initialize them with a for loop, I would not want to do this one by one, although I do not know if this is possible. For a single button image, this will be something like:
imgbtn[0] = (ImageButton)findViewById(R.id.imgButton1);
I see that the R.id.smth part is an integer. Does it say somewhere where this integer value starts with imgButtons? So that I can do something like this:
int value = R.id.imgButton1;
for(int i = 0; i < imgbtn.length; i++)
{
imgbtn[i] = (ImageButton)findViewById(value);
value++;
}
source
share