Android 检索Main.xml中的按钮组
我在Android 检索Main.xml中的按钮组,android,android-layout,android-button,Android,Android Layout,Android Button,我在main.xml中创建了九个buttonn视图,并将其命名为Button1,Button2。。。Button9..然后在我的代码中创建了Button的ArrayList,很明显,这个按钮数组将把我的按钮保存在main.xml中,根据我目前的知识,要在my main.xml中获取按钮,我需要使用findViewById方法,基本上我需要循环数组来获取按钮 ArrayList<Button> buttons; int MAXBTN = 9; for( int i = 0; i <
main.xml
中创建了九个button
n视图,并将其命名为Button1,Button2。。。Button9..
然后在我的代码中创建了Button的ArrayList
,很明显,这个按钮数组将把我的按钮保存在main.xml
中,根据我目前的知识,要在my main.xml中获取按钮,我需要使用findViewById方法,基本上我需要循环数组来获取按钮
ArrayList<Button> buttons;
int MAXBTN = 9;
for( int i = 0; i < BTN; i++ )
{
// Code here to use the findViewById method to get the button
}
ArrayList按钮;
int MAXBTN=9;
对于(int i=0;i
我的问题是我需要传递R.id.Button1。。R.id.Button3
到findViewById方法,但我需要循环这个。在findViewById
while循环中,我是否可以传递计数器
请告知。您可以试试这个
ArrayList<Button> buttons;
int MAXBTN = 9;
for( int i = 0; i < BTN; i++ )
{
String buttonID = "Button" + i+1 ;
int resID = getResources().getIdentifier(buttonID, "id", "packageName");
buttons.get(i) = ((Button) findViewById(resID));
}
ArrayList按钮;
int MAXBTN=9;
对于(int i=0;i
我想已经有同样的问题了
最好先搜索,然后再问谢谢。你的包名(在java文件的顶部区域找到)。