重複の可能性:
Android: 多くのボタン ID をエレガントに設定する方法
これは Eclipse で作成された android プログラムです。imageButton1 の代わりに文字列連結を使用しようとしましたが、役に立ちませんでした。R は生成されたクラスなので、imageButtons が配列の一部になるように編集することはできません。これを for ループに入れるにはどうすればよいですか?
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);