Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get all TableRow's in a TableLayout

I've been looking for hours on how to get all TableRow's in a TableLayout. I already know how to add and delete rows dynamically, but I need to loop over all the rows and selectively delete some of them.

I think I can come up with a work around, but I'm trying to avoid crude hacks in my app.

like image 724
eugene Avatar asked Jul 25 '10 01:07

eugene


1 Answers

Have you tried using getChildCount() and getChildAt(int) respectively?

Should be fairly easy in a loop:

for(int i = 0, j = table.getChildCount(); i < j; i++) {     View view = table.getChildAt(i);     if (view instanceof TableRow) {         // then, you can remove the the row you want...         // for instance...         TableRow row = (TableRow) view;         if( something you want to check ) {             table.removeViewAt(i);             // or...             table.removeView(row);         }     } } 
like image 167
Quintin Robinson Avatar answered Oct 04 '22 17:10

Quintin Robinson