1
私は複雑なテーブルを持っていますので、ボタンやテキストビューを追加するためにある程度の柔軟性を持たせたいと思います。 。私はLinearLayoutをプログラムでTableRowに設定しようとしていますが、実行時に行が表示されません。問題が何であるかを誰かが指摘できたら大変感謝しています。android - TableRow(LinearLayoutを含む)をテーブルに追加する
TableRow tr = new TableRow(this);
tr.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
final CheckBox checkbox = new CheckBox(this);
checkbox.setPadding(10, 5, 0, 0);
checkbox.setTextSize(TypedValue.COMPLEX_UNIT_PX, 15);
checkbox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String item_clicked_on = (String) ((TextView) view).getText();
Toast.makeText(getApplicationContext(), item_clicked_on, Toast.LENGTH_SHORT).show();
}
});
TextView tv = new TextView(this);
tv.setText(" " + count + ". " + baby.getName());
tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, 14);
tv.setPadding(10, 10, 0, 0);
tv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String item_clicked_on = (String) ((TextView) view).getText();
Toast.makeText(getApplicationContext(), item_clicked_on, Toast.LENGTH_SHORT).show();
}
});
checkbox.setLayoutParams(new LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT));
tv.setLayoutParams(new LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT));
LinearLayout linearLayout = new LinearLayout(tr.getContext());
linearLayout.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
linearLayout.addView(checkbox, new LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT));
linearLayout.addView(tv, new LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT));
tableRow.addView(linearLayout);
table.addView(tr, new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
私はこのxmlのようにしようとしています。
<TableRow android:id="@+id/tableRow3" android:layout_width="wrap_content" android:layout_height="wrap_content">
<LinearLayout android:id="@+id/linearLayout2" android:layout_width="wrap_content" android:layout_height="wrap_content">
<CheckBox android:id="@+id/checkBox1" android:layout_width="wrap_content" android:layout_height="wrap_content"></CheckBox>
<TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Choice 1" android:textColor="#FFFFFF"></TextView>
</LinearLayout>
</TableRow>
linearLayoutをTableRowに、TableRowをTableに追加する必要はありませんか? – user826323
@ user826323変数** tableRow **と** tr **をチェックするだけです。どのテーブルを**テーブル**に追加する必要がありますか?上記の答えを注意深く読んでください。 –