Tuesday, 13 August 2013

TextViews in a TableLayout

TextViews in a TableLayout

I'm trying to print a table of words in different colors. It's a 4x3
String[][] with a corresponding 4x3 int[][] for colors. Here's my code:
TableLayout tl = (TableLayout) findViewById(R.id.stroopTable);
for (int i = 0; i < curColors.length; i++) {
TableRow row = new TableRow(this);
row.setLayoutParams(new
TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,
200));
for (int j = 0; j < curColors[i].length; j++) {
TextView tv = new TextView(this);
tv.setText(curWords[i][j]);
tv.setTextColor(curColors[i][j]);
tv.setLayoutParams(new
TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,
TableRow.LayoutParams.MATCH_PARENT));
row.addView(tv);
}
tl.addView(row);
}
For some reason, it's not actually outputting anything. In the onCreate()
method, I call createGrid() (the method name) and nothing else. Do I have
to manually add the TableLayout again?
Thanks, and any help would be appreciated.

No comments:

Post a Comment