I have the following Button views
button1 = (Button) findViewById(R.id.button0);
button2 = (Button) findViewById(R.id.button1);
button3 = (Button) findViewById(R.id.button2);
button4 = (Button) findViewById(R.id.button3);
button5 = (Button) findViewById(R.id.button4);
button6 = (Button) findViewById(R.id.button5);
button7 = (Button) findViewById(R.id.button6);
button8 = (Button) findViewById(R.id.button7);
And this Button[]:
Button[] buttonViewsArray = new Button[8];
I would like to use a for loop to add the buttons into the array, but not sure how to use the i variable to then reference the correct button:
int i;
for (i = 0; i < buttonViewsArray.length; i++){
String j = "button" + i;
Button[i] = findViewById(j);
}
I thought maybe create a String which references the correct viewID?