2011-05-05 5 views
-1

Je veux ajouter des boutons dynamiquement à certaines positions, quelqu'un peut-il suggérer un exemple de code pour cela?ajouter dynamiquement des boutons?

+2

Oh mon ami! S'il vous plaît lire http://stackoverflow.com/questions/how-to-ask –

+0

Où vous voulez ajouter un bouton dynamiquement? – Pasha

Répondre

1

Voilà comment vous pouvez ajouter un bouton à un groupe à l'exécution:

final ViewGroup group = (ViewGroup)findViewById(R.id.some_group); 
final Button button = new Button(context); 
button.setText("Some text"); 
group.addView(button, 
    new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); 
-1
setContentView(R.layout.medplan_index); 

Prendre Orientation de la mise en page verticale linéaire.

LinearLayout linearLayout = (LinearLayout) findViewById(R.id.linearLayout); 

Button btn = new Button (this); 
btn.setText("button name"); 
btn.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT)); 
linearLayout.addView(btn); 
Questions connexes