0
我有很多创建的按钮,现在我想“得到”他们使用findViewById
和for循环:找了很多使用for循环(Android Studio中)按钮
public class MainActivity extends AppCompatActivity {
Array buttons[];
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
for(int i = 0; i < 10; i++){
String buttonID = "number" + i;
int resID = getResources().getIdentifier(buttonID, "id", getPackageName());
buttons[i] = ((Button) findViewById(resID));
}
}
}
但在该行
buttons[i] = ((Buttons) findViewById(resID));
我得到这个错误:
Incompatible types. Required: java.lang.reflect.Array Found: android.widget.button
如果是的话,我需要哪一个? – 404response