0
我想在一个表中动态地添加一行,只要这个函数是从不同的类中调用的。现在它使程序崩溃。我浏览了很多主题,但找不到任何东西。在TableLayout中动态添加行
public void newRow(String time, String cloc, String loc, String contact) {
TableLayout tl = (TableLayout) findViewById(R.id.table);
TableRow tr = new TableRow(this);
TextView t1 = new TextView(this);
TextView t2 = new TextView(this);
TextView t3 = new TextView(this);
TextView t4 = new TextView(this);
t1.setText(time);
t1.setText(cloc);
t1.setText(loc);
t1.setText(contact);
tr.addView(t1);
tr.addView(t2);
tr.addView(t3);
tr.addView(t4);
tl.addView(tr, TableLayout.LayoutParams.WRAP_CONTENT);
}
那么我该如何在TableLayout中添加TableRow? –
也将表格布局实例传递给方法。 – Mursaleen
它仍然崩溃 –