【问题标题】:how to add button array to layout in android? [duplicate]如何在android中将按钮数组添加到布局? [复制]
【发布时间】:2011-01-27 11:29:28
【问题描述】:

可能重复:
Add an array of buttons to a GridView in an Android application

我有按钮列表。除了当前布局之外,我还想将这些按钮添加到按钮列表中。 我可以怎么做?

【问题讨论】:

标签: java android layout button


【解决方案1】:

类似的东西?

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*/);
}

【讨论】:

  • 简单为 buttonList.add(new Button("b"));
  • 如何将按钮添加到布局而不是列表
  • 这里是链接stackoverflow.com/questions/775188/…。并将此列表添加到 tablerow 并将其添加到布局中。很简单,TableRow t = new TableRow(); t.add(按钮);布局.add(t);
猜你喜欢
  • 2017-05-31
  • 2021-01-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多