実行時に TableRow にいくつかのボタンを追加しようとしています。私のTableRowには次の構造があります:
<TableRow
android:layout_marginTop="100px"
android:gravity="bottom"
android:paddingTop="50px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/riga1">
<Button
android:textSize="32px"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/buttonOK2"
android:text="YES"
android:onClick="setResult"/>
</TableRow>
そして私のJavaコードは次のとおりです。
TableRow tr = (TableRow) findViewById(R.id.riga1);
Button b = new Button(this);
b.setText("button 1");
b.setId(1);
b.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
tr.addView(b);
Button b1 = new Button(this);
b1.setText("button 2");
b1.setId(2);
b1.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
tr.addView(b1);
しかし、これはうまくいかないようです。私のアクティビティでは、xml ファイルで定義されたボタンしか表示されません。
別の問題は、関連する TableLayout にパラメーターを設定すると、次のようになることです。
android:stretchColumns="*"
前述の TableLayout の TableRow に少なくとも 1 つのボタンを (xml ファイルに) 挿入する必要があります。そうしないと、streatchColumns の近くで「0 による除算」エラーが発生します。tableRow を空にするにはどうすればよいですか?