-UPDATE-はsetLayoutParamsでループ - ClassCastExceptionが
私はAgarwalさんが示唆されているように行われ、そして今、このエラー持っている:私は動的に15個のボタンの幅を設定するには、このコードを使用しています
04-21 11:42:01.807: E/AndroidRuntime(1456): java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParams
を。そして、あなたはそれを推測した、それは動作しません。 for
ループでエラーが発生しますが、その理由はわかりません。
Button[] buttons = new Button[16];
buttons[0] = (Button)findViewById(R.id.root2);
buttons[1] = (Button)findViewById(R.id.root3);
/* blah blah blah */
buttons[13] = (Button)findViewById(R.id.root15);
buttons[14] = (Button)findViewById(R.id.root16);
LayoutParams lp = new LayoutParams(widthOfButtons,LayoutParams.WRAP_CONTENT);
for(int x = 0; x < 16; x ++){
buttons[x].setLayoutParams(lp);
}
ありがとうございました。 16回以上のループrepaeat
15個または16個のボタンがありますか? –