Android 中的表我做错了什么?
我没有收到任何错误,但它在模拟器中没有显示任何内容。我想要一个动态表...
xml 文件的内容:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="0,1"
android:id="@+id/maintable" >
</TableLayout>
活动中添加表行和文本视图的代码:
TableLayout tl = (TableLayout) findViewById(R.id.maintable);
// Go through each item in the array
for (int current = 0; current < strAuftraege.length; current++)
{
// Create a TableRow and give it an ID
TableRow tr = new TableRow(this);
// tr.setId(100+current);
tr.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
// Create a TextView to house the name of the province
TextView labelTV = new TextView(this);
// labelTV.setId(200+current);
labelTV.setText(strAuftraege[current][0]);
// labelTV.setTextColor(Color.BLACK);
labelTV.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
tr.addView(labelTV);
// Create a TextView to house the value of the after-tax income
TextView valueTV = new TextView(this);
valueTV.setId(current);
valueTV.setText(strAuftraege[current][1]);
System.out.println(valueTV.getText().toString());
// valueTV.setTextColor(Color.BLACK);
valueTV.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
tr.addView(valueTV);
// Add the TableRow to the TableLayout
tl.addView(tr, new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
}
我的错误在哪里?
I don't get any error, but its not showing anything in the simulator. I want a dynamic table...
Content of the xml file:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="0,1"
android:id="@+id/maintable" >
</TableLayout>
Code in the activity to add the tablerows and textviews:
TableLayout tl = (TableLayout) findViewById(R.id.maintable);
// Go through each item in the array
for (int current = 0; current < strAuftraege.length; current++)
{
// Create a TableRow and give it an ID
TableRow tr = new TableRow(this);
// tr.setId(100+current);
tr.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
// Create a TextView to house the name of the province
TextView labelTV = new TextView(this);
// labelTV.setId(200+current);
labelTV.setText(strAuftraege[current][0]);
// labelTV.setTextColor(Color.BLACK);
labelTV.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
tr.addView(labelTV);
// Create a TextView to house the value of the after-tax income
TextView valueTV = new TextView(this);
valueTV.setId(current);
valueTV.setText(strAuftraege[current][1]);
System.out.println(valueTV.getText().toString());
// valueTV.setTextColor(Color.BLACK);
valueTV.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
tr.addView(valueTV);
// Add the TableRow to the TableLayout
tl.addView(tr, new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
}
Where is my error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许您需要在将 TextView 添加到时使用 TableRow.LayoutParams表行?您当前正在使用普通的旧 LayoutParams。
Perhaps you need to use TableRow.LayoutParams when adding the TextViews to the table row? You are currently using plain old LayoutParams.
使用
它代替
它将解决您的问题。
Use
in place of
It will resolve your problem.