What you can do is find an instance of TableLayout using
TableLayout layout_tbl = (TableLayout) findViewById(R.id.layout_tbl);
then with getChildCount() you can TableLayout over each child of TableLayout and TableRow , it is also better to check View with instanceof so that you don't get any NPE .
for (int i = 0; i < layout_tbl.getChildCount(); i++) { View parentRow = layout_tbl.getChildAt(i); if(parentRow instanceof TableRow){ for (int j = 0; j < parentRow.getChildCount(); j++){ Button button = (Button ) parentRow.getChildAt(j); if(button instanceof Button){ String text = button.getText().toString(); } } }
Lalit poptani
source share