Android remove view from table

If you got the error message, the specified child already has a parent. you must call removeview() on the child's parent first. The solution is remove the child from parent view.

TableLayout table = (TableLayout)findViewById(R.id.tableLayout); TableRow tr = (TableRow) table.getChildAt(table.getChildCount()-1); table.removeView(tr);
// if you don't know the parent, get the parent view first. ViewGroup parentViewGroup = (ViewGroup)tr.getParent(); parentViewGroup.removeView(tr);

0 意見: