I don't know if I fully understand your question, but here:
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
TableLayout tableLayout = new TableLayout(getApplicationContext());
TableRow tableRow;
TextView textView;
for (int i = 0; i < 4; i++) {
tableRow = new TableRow(getApplicationContext());
for (int j = 0; j < 3; j++) {
textView = new TextView(getApplicationContext());
textView.setText("test");
textView.setPadding(20, 20, 20, 20);
tableRow.addView(textView);
}
tableLayout.addView(tableRow);
}
setContentView(tableLayout);
}
This code creates a TableLayout with 3 columns and 4 rows. Basically you can declare a TableLayout in an XML file, then setContentView in XML and use findViewById to search for a TableLayout. Only TableRow and its children should be executed in Java code.
source
share