How can I dynamically create a button in Android? [duplicate]
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);
精彩评论