I have a grid of 6 dice on a board that I want to access as imageButtons in Android Studio. Each imagebutton has an ID (button1 is "ImageButton1", while button two is "ImageButton2" etc.). I would like to access these buttons in one for loop, rather than writing six semi-identical statements, something like shown below:
for (int i=0; i<6; i++) {
ImageButton c+i = (ImageButton)findViewById(R.id.imageButton+i);
}
Where imageButtton1
would be stored in the variable c1
, and so forth. Obviously, this for loop does not work as written. Is there a way to implement this?