Je suis en train d'ajouter des lignes de table dynamiquement ...... Après mon code java:Dynamiquement ajouter des lignes à la TableLayout
TableLayout tl = (TableLayout) findViewById(R.id.tablerow);
/* Create a new row to be added. */
TableRow tr = new TableRow(this);
tr.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
/* Create a Button to be the row-content. */
Button b = new Button(this);
b.setText("Dynamic Button");
b.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
/* Add Button to row. */
tr.addView(b);
/* Add row to TableLayout. */
tl.addView(tr, new TableLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
Mon code XML est
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tablerow"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableRow>
<TextView
android:id="@+id/content"
android:singleLine="false" />
</TableRow>
</TableLayout>
Mais je obtenir une erreur sur cette ligne:
final TableLayout tl = (TableLayout)findViewById(R.id.tablerow);
erreur que je reçois est ne peut pas lancer de vue à TableLayout
Toute aide sera appréciée
Pourquoi utilisez-vous le gonflage dynamique? setContentView() devrait déjà avoir fait tout le gonflement nécessaire. –
S'il vous plaît jeter un oeil sur le code ci-dessus ... j'ai édité maintenant ... toujours la même erreur apparaît "Impossible de diffuser de vue à Tablelayout" –
Post le fichier XML complet – techiServices