2010-10-20 4 views

Répondre

1

ajouter Programmatically TextView (ou View en général) à la mise en page (ou ViewGroup en général) est possible, vérifier la méthode de ViewGroup public void addView (View child, int index).

5

Solution complète:

View parent; //parent view where to add 


    ViewGroup layout=new LinearLayout(context); 
    layout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); 
    TextView tv1=new TextView(context); 
    tv1.setText("Test1"); 
    TextView tv2=new TextView(context); 
    tv2.setText("Test2"); 
    layout.addView(tv1); 
    layout.addView(tv2); 
    parent.addView(layout); 
+1

Où est la déclaration de "contexte"? Est-il initialiser n'importe où –