super.onCreate(icicle);
// create linear layout
mLinearLayout = new LinearLayout(this);
mLinearLayout.setOrientation(LinearLayout.VERTICAL);
mLinearLayout.setLayoutParams(new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
// add a button above
Button buttonAbove = new Button(this);
buttonAbove.setLayoutParams(
new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
buttonAbove.setText("button above list");
mLinearLayout.addView(buttonAbove);
// add a list view to it
mListView = new ListView(this);
mListView.setLayoutParams(new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
mListView.setDrawSelectorOnTop(false);
mListView.setItemsCanFocus(true);
mListView.setLayoutParams((new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
0,
1f)));
List<String> bodies = Lists.newArrayList(
getBody("zero hello, my name is android"),
getBody("one i'm a paranoid android"),
getBody("two i robot. huh huh."),
getBody("three not the g-phone!"));
mListView.setAdapter(new MyAdapter(this, bodies));
mLinearLayout.addView(mListView);
// add button below
Button buttonBelow = new Button(this);
buttonBelow.setLayoutParams(
new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
buttonBelow.setText("button below list");
mLinearLayout.addView(buttonBelow);
setContentView(mLinearLayout);