Possible Duplicate:
android: how to elegantly set many button IDs
This is an android program made with eclipse. I’ve tried using string concatenation in the place of imageButton1 to no avail. R is the generated class so I cannot go into it and edit it so that the imageButtons are part of an array.
How can I put this into a for loop?
seatButton[0] = (ImageButton) findViewById(R.id.imageButton1);
seatButton[1] = (ImageButton) findViewById(R.id.imageButton2);
seatButton[2] = (ImageButton) findViewById(R.id.imageButton3);
seatButton[3] = (ImageButton) findViewById(R.id.imageButton4);
seatButton[4] = (ImageButton) findViewById(R.id.imageButton5);
seatButton[5] = (ImageButton) findViewById(R.id.imageButton6);
seatButton[6] = (ImageButton) findViewById(R.id.imageButton7);
seatButton[7] = (ImageButton) findViewById(R.id.imageButton8);
seatButton[8] = (ImageButton) findViewById(R.id.imageButton9);
seatButton[9] = (ImageButton) findViewById(R.id.imageButton10);
You can also use
getResources().getIdentifier(String name, String defType, String defPackage)where name is the resource name, defType is drawable and defPackage is your full package name.Which would result in something like: