Possible Duplicate:
how to add button dynamically in android?
How can I dynamically create a button in Android?
Firstly add the appropriate import to your Activity:
import android.widget.Button;
Then create a new button object within the onCreate method:
Button myButton = new Button(this);
myButton.setText("Press Me");
Finally add the button to the layout:
LinearLayout layout = (LinearLayout) findViewById(R.id.layout1);
layout.addView(myButton);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With