How to clear all rows from a TableLayout?
If you want to remove all the rows but the first row (which is often used as the header), you can use:
tableLayout.removeViews(1, Math.max(0, tableLayout.getChildCount() - 1));
You need to call removeAllViews() on each TableRow:
int count = table.getChildCount();
for (int i = 0; i < count; i++) {
View child = table.getChildAt(i);
if (child instanceof TableRow) ((ViewGroup) child).removeAllViews();
}
It sounds like you might be calling removeAllViews()
on the whole LinearLayout
and not the particular TableLayout
you want to clear. Double check you have some thing like:
myLinearLayout.someTableView.removeAllViews()