0

这是我的代码的一部分,它必须显示包含多个项目的表格视图,但它没有显示任何内容。

TableLayout tableView = (TableLayout) findViewById(R.id.tableLayoutUsers);
          TableRow tr = new TableRow(this);
          LayoutParams rowLayoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
          tr.setLayoutParams(rowLayoutParams);

          TextView name = new TextView(this);
          name.setText(userClass.getUsername());
          LayoutParams dateLayParam = new LayoutParams(LayoutParams.WRAP_CONTENT); // , LayoutParams.FILL_PARENT);
          name.setLayoutParams(dateLayParam);

          tr.addView(name);
          tableView.addView(tr, new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
          tr.setClickable(true);

有什么问题?谢谢

4

2 回答 2

1

尝试:name.setTextColor(Color.BLACK);

于 2013-08-23T10:47:37.853 回答
0

试试这个代码

    TableLayout tl = (TableLayout) findViewById(R.id.tableLayoutUsers);

    TableRow tr = new TableRow(this);
    tr.setId(100 + 0);

    TableLayout.LayoutParams params = new TableLayout.LayoutParams(
            TableLayout.LayoutParams.WRAP_CONTENT,
            TableLayout.LayoutParams.WRAP_CONTENT, 1f);

    TextView text = new TextView(this);
    text.setText("Meenal");
    text.setTextColor(Color.BLACK);

    TableRow.LayoutParams imageParams = new TableRow.LayoutParams();

    tr.addView(text);

    tr.setLayoutParams(params);
    tl.addView(tr, params);
于 2013-08-23T13:21:49.873 回答