开发者

Problem in code for adding rows - pass through code without exception but nothing shows

I have code for programmatically adding rows to table

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);
                        la开发者_开发百科belTV.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));
                    }   

and I have xml

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

and I pass through function without exception, I have debugged, but nothing shows on screen. Can somebody tell me what I have done wrong ?


Perhaps, you need to have other views you want to display on the row inside the TableLayout. Try adding your TextView inside the TableLayout.

Or in your existing code

tl.addView(tr);

Since once you set the parameters for the TableRow

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜