2010-10-18 107 views
0

我有一个动态表格布局在OnCreate()中创建。每次活动恢复时,表格行中的数据都会改变,所以我想销毁表格行并创建新行。 我该怎么做?谢谢!!!动态重新创建表格布局

这里是OnCreate中创建表的部分是什么样子:

tableLayout tl = new TableLayout(this); 

    for (i = 0; i < numberOfVariables; i++) { 

     TableRow tr = new TableRow(this); 

     CheckBox cb = new CheckBox(this); 
     tr.addView(cb); 

     TextView dv = new TextView(this); 
     tr.addView(dv); 

     EditText et = new EditText(this); 
     tr.addView(et); 

     tl.addView(tr); 
    } 

    ll.addView(tl); 

回答

2

只需使用tl.removeAllViews();,然后重新创建行。

+0

我怎么会错过? – 2010-10-18 16:57:26

+0

非常感谢!那就是诀窍。 – 2010-10-18 16:57:41