androidandroid-layoutandroid-tabhost

Adding views to an activity programmatically


I have this code on the onCreate() of an Activity that is inside a Tab:

String[] info = getResources().getStringArray(R.array.fc_1);
TextView q = new TextView(this);
q.setText(info[0]);

TextView a1 = new TextView(this);
a1.setText(info[1]);

TextView a2 = new TextView(this);
a2.setText(info[2]);

TextView a3 = new TextView(this);
a3.setText(info[3]);

LinearLayout linlay = new LinearLayout(this);
linlay.addView(q);
linlay.addView(a1);
linlay.addView(a2);
linlay.addView(a3);
setContentView(linlay);

What happens is that only the first textview gets shown, with the correct value of info[0], but the others textviews just aren't there.

Any ideas what I might be doing wrong?


Solution

  • Default orientation of LinearLayout is horizontal. So the other TextViews are to the right of the first which takes all the space. Change the orientation of the LinearLayout to vertical.