【发布时间】:2012-05-17 01:22:37
【问题描述】:
我在使用 View leader 时遇到问题,我不确定第二个参数应该是什么
TableLayout leaderTable = (TableLayout)findViewById(R.id.leaderTable);
TableRow tr = new TableRow(this);
tr.setId(i);
tr.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
View leader = new View(UserView.this, null, R.id.leaderLayout);
TextView number = (TextView)leader.findViewById(R.id.numberView);
number.setText(String.valueOf(i+1));
tr.addView(leader);
leaderTable.addView(tr);
问题是我的TextView 为空,尽管它是leader. 的子视图
对这个问题很困惑,这是我的 XML
<TableLayout
android:id="@+id/leaderTable"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
</TableLayout>
我需要对 XML 做更多的事情吗?我不需要在其中包含表格行吗?
R.id.leaderLayout 是它自己的 xml 文件,具有该 id 的线性布局
【问题讨论】:
标签: android xml view android-linearlayout tablelayout