How to add a button control to an android xml view at runtime?

前端 未结 6 519
陌清茗
陌清茗 2020-12-11 16:26

I have an android xml layout, main.xml. I would like to add controls to this layout at runtime (I would like to add a series of additional linear layouts that contain button

6条回答
  •  -上瘾入骨i
    2020-12-11 17:18

    Try this :

    LinearLayout ll =(LinearLayout)findViewById(R.id.linlay);
    Button b = new Button(this);
    b.setText("Hello");
    l.addView(b);
    

    This might help you

提交回复
热议问题