Is Listing 29.4 awful?


#1

Is this just me, or code is really unsafe:

TableLayout tableLayout = (TableLayout) view.findViewById(R.id.fragment_remote_control_table_layout); int number = 1; for (int i = 2; i < tableLayout.getChildCount() - 1; i++) { TableRow row = (TableRow) tableLayout.getChildAt(i); { for (int j = 0; j < row.getChildCount(); j++) { Button button = (Button) row.getChildAt(j); button.setText("" + number); button.setOnClickListener(numberButtonListener); number++; } } }
What if design will change in future? I believe, we have to visit every element in table and check, if this element we need. And don’t rely on order in table layout.