Get all TableRow's in a TableLayout

前端 未结 5 917
春和景丽
春和景丽 2021-02-01 16:10

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 sele

5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-01 16:30

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

提交回复
热议问题