Bonjour,

Je tente d'ajouter dynamiquement une ligne dans un TableLayout, mais sans succès (rien n'apparait à l'affichage, pas d'erreur).

Voila le code:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tableMain"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
     <TableRow
          android:layout_width="fill_parent"
          android:layout_height="wrap_content">
 
          <Button android:text="Static Button"/>
     </TableRow>
</TableLayout>
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
TableLayout tableMain= (TableLayout) findViewById(R.id.tableMain);
        TableRow tr = new TableRow(this);
        tr.setId(5);
        tr.setLayoutParams(new LayoutParams(
                LayoutParams.FILL_PARENT,
                LayoutParams.WRAP_CONTENT));   
 
        ImageView icon = new ImageView(this);
        icon.setLayoutParams(new LayoutParams(
                LayoutParams.FILL_PARENT,
                LayoutParams.WRAP_CONTENT));
        icon.setImageResource(R.drawable.image);
        tr.addView(icon);
 
        TextView texteCol = new TextView(this);
        texteCol.setText("mon texte");
        texteCol.setLayoutParams(new LayoutParams(
                LayoutParams.FILL_PARENT,
                LayoutParams.WRAP_CONTENT));
        tr.addView(texteCol);
 
        TextView limitePrixCol = new TextView(this);
        limiteCol.setText(String.valueOf(15.5));
        limiteCol.setLayoutParams(new LayoutParams(
                LayoutParams.FILL_PARENT,
                LayoutParams.WRAP_CONTENT));
        tr.addView(limiteCol);
 
        tableMain.addView(tr, new TableLayout.LayoutParams(
                LayoutParams.FILL_PARENT,
                LayoutParams.WRAP_CONTENT));

Cela fonctionne-t-il chez vous?
Merci