私はJavaとAndroidを始めたばかりです。
以下は私のコードで、アクティビティにすべてのボタンを追加して非表示にします。質問: とにかく、アクティビティにすべてのボタンをリストせずに自動的に追加する方法はありますか? listA.addall を見ましたが、アクティビティをコレクションとして追加する方法がわかりませんでした。
これの合理的な理由は、ボタンの数を変更してもコードが機能するようにしたい場合があるからです。
public void setup2(){
List<Button> listA = new ArrayList<Button>();
listA.add((Button)findViewById(R.id.button1));
listA.add((Button)findViewById(R.id.button2));
listA.add((Button)findViewById(R.id.button3));
listA.add((Button)findViewById(R.id.button4));
listA.add((Button)findViewById(R.id.button5));
for (Button item : listA)
item.setVisibility(View.INVISIBLE);
}