ボタンにいくつかのリソースを適用して背景を変更するアプリケーションがあります。
すべて正常に動作しますが、アプリケーションが onPause の後に onResume に移行すると、背景を設定できなくなります。
18 個のボタンのセットがあり、onResume にいるときは次のように呼び出します。
for (int i = 0; i < max; i++) {
Button b = l.get(i);
b.setBackgroundResource(R.color.green);
}
li には、 から取得したすべてのボタンのリストがありますfindViewById()
。
これは for の最後の要素でのみ機能し、他の要素では機能しません。
何か案が?
** 編集 **
これは、配列を作成するために使用するコードです
btn_1 = (Button)findViewById(R.id.btn_1);
btn_1.setOnClickListener(this);
l.add(btn_1);
これはすべてのボタンで繰り返されます。
** 2 回目の編集 **
public void onResume() {
btn_1 = (Button)findViewById(R.id.btn_1);
btn_1.setOnClickListener(this);
l = new ArrayList<Button>();
l.add(btn_1);
...
for (int i = 0; i < max; i++) {
Button b = l.get(i);
b.setBackgroundResource(R.color.green);
}
}
で同じことが行われonCreate()
ます。