I've got a class whose content is set to a layout which has a few buttons and a TableLayout.
The real work that makes the TableLayout is in a separate static helper class, which has a method that returns the desired table.
However, the table is not displaying. What humiliatingly simple fact am I missing?
Here is the class whose content is set to the layout:
public class TesterActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TableLayout table = (TableLayout) findViewById(R.id.table);
table = TableHelper.getTable_BINARY_NUMBERS(getApplicationContext(), 5, 25);
}
}
And here is the helper class that creates the Table's meat:
public class TableHelper {
public static TableLayout getTable_BINARY_NUMBERS(Context context, int numRows, int numCols) {
TableLayout table = new TableLayout(context);
table.setStretchAllColumns(true);
table.setShrinkAllColumns(true);
TableRow[] rows = new TableRow[numRows];
for (int row=0; row<numRows; row++) {
rows[row] = new TableRow(context);
for (int col=0; col<numCols-1; col++) {
TextView num = new TextView(context);
num.setText("0");
rows[row].addView(num);
}
TextView rowText = new TextView(context);
rowText.setText("Row " + (row + 1));
rowText.setTextAppearance(context, android.R.style.TextAppearance_Small);
rows[row].addView(rowText);
rows[row].setPadding(0, 50, 0, 0);
table.addView(rows[row]);
}
return table;
}
}
Instead of returning a new table layout, pass the one you get right away to your getTable_BINARY_NUMBERS()
and modify it in your method instead of returning a completely new one.