Reputation: 12582
Here is my code. In the resulting screen it shows only the first TextView. Not the second one. Im kind of new to Android and please give a help.
public class Details extends Activity {
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
TextView label = new TextView(this);
label.setText("Moves");
label.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
label.setTextSize(20);
TextView label2 = new TextView(this);
label2.setText("Time");
label2.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
label2.setTextSize(20);
LinearLayout ll = new LinearLayout(this);
ll.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
ll.setOrientation(LinearLayout.VERTICAL);
ll.addView(label);
ll.addView(label2);
setContentView(ll);
}
}
Upvotes: 1
Views: 2988
Reputation: 13541
You forgot to tell the LinearLayout how to stack its children (Orientation). Without that it won't stack them at all and will ONLY display the first item (I believe).
http://developer.android.com/reference/android/widget/LinearLayout.html#setOrientation(int)
Upvotes: 2