0
可能重複:
Add an array of buttons to a GridView in an Android application如何在android中添加按鈕數組來佈局?
我有按鈕列表。除了當前的佈局以及setOnclickListener到按鈕列表之外,我還想添加這些按鈕。 我可以怎麼做?
可能重複:
Add an array of buttons to a GridView in an Android application如何在android中添加按鈕數組來佈局?
我有按鈕列表。除了當前的佈局以及setOnclickListener到按鈕列表之外,我還想添加這些按鈕。 我可以怎麼做?
這樣的事情?
ArrayList<Button> buttonList = new ArrayList<Button>();
buttonList.add(new Button("b1"));
buttonList.add(new Button("b2"));
buttonList.add(new Button("b3")); ...
for(Button b : buttonList) {
b.setOnclickListener(/*listener here*/);
}
你會發現在相似:http://stackoverflow.com/questions/775188/add-an-array-of-buttons-to-a-gridview-in-an-android-application – 2011-01-27 11:32:41
使用循環,也許? – 2012-11-06 23:12:45