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
它仍然崩潰 –