Deleting dynamically added rows was a bit tricky at the first. I found my solution with storing the rows in ArrayList so I can easily remove them from the table. Just look at the code:
private ArrayList<TableRow> rows; rows = new ArrayList<TableRow>(); //When creating and adding the row to the table save it also to the ArrayList rows.add(row); //Clear the dynamically added rows whenever we need it private void clearTable(){ if (rows.size() > 0) { for (int i = 0; i < rows.size(); i++) table.removeView(rows.get(i)); } rows.clear(); }
Adding rows to a table is described in Part I