Dynamic tables with Android – Part II

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

//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));

Adding rows to a table is described in Part I

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.