If you try to remove TableRows the ID Counter will decrease so pls use this loop for removing ... else if you dont want to remove you can use some of the loops above :D
TableLayout table = (TableLayout) findViewById(R.id.tblScores);
for(int i = 0; i < table.getChildCount(); i = 0)
{
View child = table.getChildAt(0);
if (child != null && child instanceof TableRow)
{
TableRow row = (TableRow) child;
row.removeAllViews();
table.removeViewAt(i);
}
}
This clears all rows!
I think your main problem is if you remove rows that all rows will be newly placed so that the row with the ID = 5 is now ID = 4 if you delete the row with ID = 3
so maybe you have to reset the counter and iterate again or you generate the table new after you cleared all rows