Таблица в Android, что я делаю не так? - PullRequest
1 голос
/ 18 марта 2011

Я не получаю никакой ошибки, но в симуляторе ничего не отображается.Я хочу динамическую таблицу ...

Содержимое 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));
                }

Гдемоя ошибка?

Ответы [ 2 ]

1 голос
/ 07 мая 2011

Используйте

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

Это решит вашу проблему.

1 голос
/ 18 марта 2011

Возможно, вам нужно использовать TableRow.LayoutParams при добавлении TextViews в строку таблицы?Вы используете старые старые LayoutParams.

...