可能性の重複:
Add an array of buttons to a GridView in an Android applicationボタン配列をアンドロイドのレイアウトに追加する方法は?
私はボタンのリストを持っています。私は現在のレイアウトに加えてこれらのボタンを追加したいし、ボタンリストにsetOnclickListenerも追加したい。 どうすればいいですか?
可能性の重複:
Add an array of buttons to a GridView in an Android applicationボタン配列をアンドロイドのレイアウトに追加する方法は?
私はボタンのリストを持っています。私は現在のレイアウトに加えてこれらのボタンを追加したいし、ボタンリストに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 –
を使用しますループ、多分? –