Android 中的表我做错了什么?

发布于 2024-10-24 00:52:09 字数 2373 浏览 8 评论 0原文

我没有收到任何错误,但它在模拟器中没有显示任何内容。我想要一个动态表...

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我早已燃尽 2024-10-31 00:52:09

也许您需要在将 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.

微凉徒眸意 2024-10-31 00:52:09

使用

tr.addview(tv1,new TableRow.LayoutParam(
      android.widget.TableLayout.LayoutParam.FILLPARENT,
      android.widget.TableLayout.LayoutParam.WILLPARENT) 

它代替

tr.addview(tv1,new LayoutParam(
      Layoutparam.FILLPARENT,
      LayoutParam.WRAPPARENT);

它将解决您的问题。

Use

tr.addview(tv1,new TableRow.LayoutParam(
      android.widget.TableLayout.LayoutParam.FILLPARENT,
      android.widget.TableLayout.LayoutParam.WILLPARENT) 

in place of

tr.addview(tv1,new LayoutParam(
      Layoutparam.FILLPARENT,
      LayoutParam.WRAPPARENT);

It will resolve your problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文