1

エラーは発生しませんが、シミュレーターには何も表示されません。動的テーブルが欲しい...

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>

tablerows と 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));
                }

私のエラーはどこですか?

4

2 に答える 2

1

使用する

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);

それはあなたの問題を解決します。

于 2011-05-07T08:52:38.067 に答える
1

テーブル行に TextViews を追加するときに、TableRow.LayoutParamsを使用する必要があるのではないでしょうか? 現在、プレーンな古い LayoutParams を使用しています。

于 2011-03-18T13:24:18.210 に答える