这是我的代码的一部分,必须显示包含多个项目的表格视图,但它没有显示任何内容。
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);
有什么问题? 感谢
答案 0 :(得分:1)
尝试:name.setTextColor(Color.BLACK);
答案 1 :(得分: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);