Estoy tratando de comprender cómo agregar dinámicamente columnas y filas a una tabla de diseño.¿Cómo crear dinámicamente columnas en una presentación de tablas?
Tengo este sencillo ejemplo. Sin embargo, solo muestra la primera columna cuando se ejecutó.
¿Puede alguien decirme qué falta para mostrar cuatro columnas en lugar de una?
package com.apollo.testtablelayout;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
public class TestTableLayoutActivity extends Activity {
/** Called when the activity is first created. */
String col1;
String col2;
String col3;
String col4;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TableLayout tl = (TableLayout) findViewById(R.id.tableLayout1);
for (int x = 1; x < 10; x++) {
col1 = "(" + x + ") Column 1";
col2 = "(" + x + ") Column 2";
col3 = "(" + x + ") Column 3";
col4 = "(" + x + ") Column 4";
TableRow newRow = new TableRow(this);
TextView column1 = new TextView(this);
TextView column2 = new TextView(this);
TextView column3 = new TextView(this);
TextView column4 = new TextView(this);
column1.setText(col1);
newRow.addView(column1);
newRow.addView(column2);
newRow.addView(column3);
newRow.addView(column4);
tl.addView(newRow, new TableLayout.LayoutParams());
}
}
}