0

Possible Duplicate:
Add an array of buttons to a GridView in an Android application

I have Button List. I want to add these buttons in addition to current layout and also setOnclickListener to Button list. I can do how?

Community
  • 1
  • 1
ali
  • 1
  • 1
  • 1
  • You will find similar at: http://stackoverflow.com/questions/775188/add-an-array-of-buttons-to-a-gridview-in-an-android-application – Harry Joy Jan 27 '11 at 11:32

1 Answers1

0

Something like that ?

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*/);
}
  • simply as buttonList.add(new Button("b")); –  Jan 27 '11 at 11:58
  • how can I add buttons to layout not list – ali Jan 27 '11 at 12:02
  • here is link http://stackoverflow.com/questions/775188/add-an-array-of-buttons-to-a-gridview-in-an-android-application. and this list to tablerow and add it to the layout. Simple, TableRow t = new TableRow(); t.add(buttons); layout.add(t); –  Jan 27 '11 at 12:06