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