【发布时间】:2016-06-13 18:18:48
【问题描述】:
出了点问题,首先我为表格行单独创建了 xml 文件,它不起作用,然后我以编程方式创建了表格行和文本视图,再次运行时它不显示,我无法得到我的代码有什么问题
table = (TableLayout) findViewById(R.id.goodsTable);
for (int i = 0; i < attrName.length; i++) {
TableRow tr = new TableRow(getApplicationContext());
tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
TextView atName = new TextView(getApplicationContext());
atName.setText(attrName[i]);
tr.addView(atName);
table.addView(tr, new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
}
table.requestLayout();
【问题讨论】:
-
这是我上面提到的代码,使用 xml 文件 TableRow row = (TableRow) LayoutInflater.from(getApplicationContext()).inflate(R.layout.attribute_row, table, false); ((TextView) row.findViewById(R.id.attributeName)).setText(attrName[i]); ((TextView) row.findViewById(R.id.attributeValue)).setText(barcode); table.addView(row, new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
标签: android android-tablelayout tablerow