Проблема в коде для добавления строк - пройти через код без исключения, но ничего не показывает - PullRequest
0 голосов
/ 25 июля 2011

У меня есть код для программного добавления строк в таблицу

TableLayout tl = (TableLayout) findViewById(R.id.tblLog);
                    List<String> s=new LinkedList<String>();
                    s.add("test1");
                    s.add("test2");
                    s.add("test3");
                    // Go through each item in the array
                    int id=0;
                    for (String temp:s)
                    {
                        id++;
                        // Create a TablView v = new View(this);eRow and give it an ID
                        TableRow tr = new TableRow(currentActivity);  
                        TableLayout.LayoutParams tableRowParams=
                          new TableLayout.LayoutParams
                          (TableLayout.LayoutParams.FILL_PARENT,TableLayout.LayoutParams.WRAP_CONTENT);

                        int leftMargin=10;
                        int topMargin=2;
                        int rightMargin=10;
                        int bottomMargin=2;

                        tableRowParams.setMargins(leftMargin, topMargin, rightMargin, bottomMargin);

                        tr.setLayoutParams(tableRowParams);
                        // Create a TextView to house the name of the province
                        TextView labelTV = new TextView(currentActivity);
                        labelTV.setId(200+id);
                        labelTV.setText(temp);
                        labelTV.setTextColor(Color.RED);
                        labelTV.setLayoutParams(new LayoutParams(
                                LayoutParams.FILL_PARENT,
                                LayoutParams.WRAP_CONTENT));
                        tr.addView(labelTV);
                        tl.addView(tr, new TableLayout.LayoutParams(
                                LayoutParams.FILL_PARENT,
                                LayoutParams.WRAP_CONTENT));
                    }   

, и у меня есть xml

    <TableLayout
        android:id="@+id/tblLog"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
>
    </TableLayout>

, и я без исключения пропускаю функцию, отлаживаю, но ничего не отображается наэкран.Может кто-нибудь сказать мне, что я сделал не так?

1 Ответ

1 голос
/ 25 июля 2011

Возможно, вам нужно иметь другие представления, которые вы хотите отобразить в строке внутри TableLayout. Попробуйте добавить свой TextView в TableLayout.

Или в вашем существующем коде

tl.addView(tr);

Так как однажды вы установили параметры для TableRow

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...