i want to add some buttons dynamically at some positions开发者_如何学编程,can anyone suggest a sample code for this??
That's how you can add a button to a group at runtime:
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));
setContentView(R.layout.medplan_index);
Take Orientation of linear Layout vertical.
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);
精彩评论