开发者

dynamically add buttons?

开发者 https://www.devze.com 2023-03-02 19:01 出处:网络
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:

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号