Get all TableRow's in a TableLayout

前端 未结 5 1045
春和景丽
春和景丽 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:45

    I have been looking for the same thing for a while. For me, I was looking to how to check views in my table layout. I did this by:

        //This will iterate through your table layout and get the total amount of cells.
        for(int i = 0; i < table.getChildCount(); i++)
        {
            //Remember that .getChildAt() method returns a View, so you would have to cast a specific control.
            TableRow row = (TableRow) table.getChildAt(i); 
            //This will iterate through the table row.
            for(int j = 0; j < row.getChildCount(); j++)
            {
                Button btn = (Button) row.getChildAt(j);
                //Do what you need to do.
            }
        }
    

提交回复
热议问题