Add this code to OnCreate method of the activity code file:
// The layout and buttons are declared as
// final because they are referenced in the
// event handler in the inner class.
final LinearLayout layout = (LinearLayout)
findViewById(R.id.linear_layout);
LinearLayout.LayoutParams params =
new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT);
//CharSequence[ ] months = {
String[ ] months = {
"January ", "February", "March ", "April ", "May ",
"June ", "July ", "August ", "September",
"October ", "November", "December "};
for (int i = 1; i <= 12; i++) {
final Button btn = new Button(this);
btn.setId(i);
btn.setText(months[i - 1]);
btn.setLayoutParams(params);
layout.addView(btn);
}