リソースIDをループで取得
for(int i = 0; i < btnTable.length; i++){ String btnId = "btn"+(i+1); int resId = getResources().getIdentifier(btnId, "id", getPackageName()); btnTable[i] = (Button)findViewById(resId); btnTable[i].setOnClickListener(this); }
for(int i = 0; i < btnTable.length; i++){ String btnId = "btn"+(i+1); int resId = getResources().getIdentifier(btnId, "id", getPackageName()); btnTable[i] = (Button)findViewById(resId); btnTable[i].setOnClickListener(this); }