Android 如何清除表格布局的先前内容?

Android 如何清除表格布局的先前内容?,android,Android,我已经用xml创建了一个表布局。在运行时,我使用的条件是,在第一种情况下,我填充表布局。然而,在第二种情况下,我再次将内容添加到相同的布局中。它们在布局的末尾被加起来。但是我需要清除布局的先前内容。 我可以使用这些removeallview()方法,但它不起作用。。我的代码是 ll=(LinearLayout)findViewById(R.id.linear1); for (int i = 0; i <= 1; i++) { table=new TableLay

我已经用xml创建了一个表布局。在运行时,我使用的条件是,在第一种情况下,我填充表布局。然而,在第二种情况下,我再次将内容添加到相同的布局中。它们在布局的末尾被加起来。但是我需要清除布局的先前内容。 我可以使用这些removeallview()方法,但它不起作用。。我的代码是

ll=(LinearLayout)findViewById(R.id.linear1);

    for (int i = 0; i <= 1; i++) {

        table=new TableLayout(mContext);

        TableLayout.LayoutParams tableParams=  new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT,TableLayout.LayoutParams.WRAP_CONTENT);
        int leftMargin=0;
        int topMargin=0;
        int rightMargin=0;
        int bottomMargin=0;
        tableParams.setMargins(leftMargin, topMargin, rightMargin, bottomMargin);
        table.setLayoutParams(tableParams);

        lf_header = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        header_view = lf_header.inflate(R.layout.header, null); 

        DBAdapter dbAdapter=DBAdapter.getDBAdapterInstance(this);
        try {
            dbAdapter.createDataBase();
        } catch (IOException e) {
            Log.i("*** select ",e.getMessage());
        }
        dbAdapter.openDataBase();
        if(i==0){
            ((TextView) header_view.findViewById(R.id.header_txt1)).setText("Over Due");
            header_view.setBackgroundColor(Color.RED);
            table.addView(header_view);
ll.addView(table);
ll=(LinearLayout)findViewById(R.id.linear1);

对于(int i=0;itry
table.removeAllViewsInLayout()

int count=table.getChildCount();

对于(int i=0;itry
table.removeAllViewsInLayout()

int count=table.getChildCount();

对于(int i=0;i当单击“全部”按钮时,此表格布局已创建。单击其他按钮后,我将再次单击“全部”按钮。请建议我将删除的位置或使用表格的位置。removeAllViewsInLayout()?当需要删除时,只需在单击“全部”按钮时调用它即可创建此表格布局。单击其他按钮后,我将再次单击“所有”按钮。请建议我将删除的位置或whr以使用table.removeAllViewsInLayout()?当需要删除时,只需调用它即可
int count=table.getChildCount();
         for(int i=0;i<count;i++)
             table.removeView(layout.getChildAt(i));