首先,你必须创建一个textview的实例,向它添加文本,然后将它添加到表中。事情是这样的:
类声明:
public class Cell extends TextView{
public Cell(Context context) {
super(context);
}
}
创建这个类的一个实例,并将其添加到表:
TableLayout table;
table = (TableLayout) findViewById(R.id.table_id);
// New instance of a table row
TableRow row = new TableRow(getActivity());
// New instances of our new class
Cell txt1 = new Cell(this);
Cell txt2 = new Cell(this);
Cell txt3 = new Cell(this);
// Add them to a row
row.addView(txt1,0); // Second argument is the column of the table
row.addView(txt2,1);
row.addView(txt3,2);
// Add the row to the table
tbl.addView(row);
该表是包含其他视图的视图。
希望这会有所帮助!
尝试向东西发生的部分添加更多代码。 –
对不起。该链接似乎已被取消。请参阅编辑。 –