开发者

TableLayout generated by code isn't displaying

I have a need to generate a table layout dynamically using code. I can't get it to display. I've reduced the table generation code segment down to its basics to try and nut it out but even this greatly simplified version isn't working (ie. doesn't display). Can someone please point out what I'm doing wrong? Thanks.

public class TableByCodeTest extends Activity{

    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    TableLayout tableLayout = new TableLayout(this);
    tableLayout.setLayoutParams(
        new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

    TableRow firstTableRow = new TableRow(this);
    firstTab开发者_运维问答leRow.setLayoutParams(
        new TableRow.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
    TextView title = new TextView(this);
    title.setText(R.string.title);
    title.setLayoutParams(
        new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));

    firstTableRow.addView(title);
    tableLayout.addView(firstTableRow);
    setContentView(tableLayout);

    }
}


Change the line:

firstTableRow.addView(title);

to

firstTableRow.addView(title,new TableRow.LayoutParams(0));

To add it to row 0.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜