I have what I thought was very simple code:

//Get LinearLayout declared in XML
final LinearLayout mainLayout = (LinearLayout)
findViewById(R.id.linLayout);

//Create a LinearLayout to display text in.
LinearLayout myLayout = new LinearLayout(this);
myLayout.setLayoutParams(new
LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));

TextView myTestText = new TextView(this);
myTestText.setText("This should be in a LinearLayout.");
myTestText.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));

myLayout.addView(myTestText);

mainLayout.addView(myLayout);

//Create a TableLayout to display text in
TableLayout myTable = new TableLayout(this);
myTable.setLayoutParams(new
TableLayout.LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));

TableRow myRow = new TableRow(this);
myRow.setLayoutParams(new
TableRow.LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));

TextView myText = new TextView(this);
myText.setText("This should be in a table");
myText.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));

myRow.addView(myText);

myTable.addView(myRow);

mainLayout.addView(myTable);

//Create another LinearLayout to display text in.
LinearLayout myOtherLayout = new LinearLayout(this);
myOtherLayout.setLayoutParams(new
LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));

TextView myOtherTestText = new TextView(this);
myTestOtherText.setText("This should also be in a LinearLayout.");
myTestOtherText.setLayoutParams(new
LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

myOtherLayout.addView(myOtherTestText);

mainLayout.addView(myOtherLayout);

This throws no errors at all, however I only see the linear layouts
with the text, "This should be in a LinearLayout", and right below
that (the mainLayout's orientation is set to vertical, hence it being
below) is, "This should also be in a LinearLayout" on the screen, the
table does not show at all.
I've search around a lot on this, and the only thing I can find is to
make sure that the TableRow using TableRow.LayoutParams. Any ideas why
the table I add to this view just isn't displaying at all? My ultimate
goal is to have alternating LinearLayouts and TableLayouts generated
dynamically, which I know works with XML (I designed a static layout
in XML and it worked fine), it is just when I try to add the
TableLayouts dynamically that I'm running into this issue.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to