How to get all Buttons ID's in one time on Android
问题 I have 16 Button s in my Activity and I have to initialize those inside onCreate(). Is there any way to initialize all buttons in one single line code?(loops etc.) Code should take all buttons R.id. from XML Layout and process.... 回答1: Let's say you named your button button_0, button_1, .. button_15 . You can do: for (int i = 0; i < 16; i++) { int id = getResources().getIdentifier("button_"+i, "id", getPackageName()); button[i] = (Button) findViewById(id); } 回答2: Well, if all 16 of those