views:

54

answers:

1

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.

+3  A: 

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++){
    // then, you can remove the the row you want...
    // for instance...
    TableRow row = getChildAt(i);
    if( something you want to check ) {
        removeViewAt(i);
        // or...
        removeView(row);
    }
}
Quintin Robinson
I haven't seen anything in the Android SDK documentation about these methods (maybe I just overlooked it). I'll try that and let you know.Thanks for your help.
eugene
@eugene Absolutely, just to note, I did link those method references to the actual sdk documentation for them. Also it looks like the example that was added to my answer is in context of extending the `TableLayout` rather then using a reference of the view, just FYI. One final note, there are caveats if actually removing items from a collection in a loop (index recalculations and the like) so beware.
Quintin Robinson