You need to create the layout of the view in which you want the button to appear. Even something like
Let's say you're storing the definition in a file called main.xml in your res/layout directory.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button android:text="Button01" android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout>
Then within your activity, you need to do the following:
public class Main extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Replace this with the name of your xml file dictating layout
setContentView(R.layout.main);
}
}
See the Hello Views tutorial; very useful. http://developer.android.com/guide/tutorials/views/index.html
If you're asking something different, like programmatically adding a button to an existing view, I'm not sure about that. In that case you might want to have the button start off as hidden and then reveal it when you need it.