How to add a button dynamically in Android?


Question

How to add a button dynamically in Android?

1
113
7/15/2015 5:46:07 AM

Button myButton = new Button(this);
myButton.setText("Push Me");

LinearLayout ll = (LinearLayout)findViewById(R.id.buttonlayout);
LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
ll.addView(myButton, lp);

Have a look to this example

125
12/19/2012 11:15:16 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon