开发者

Rows added to table are not showing up

This has been asked before, but I have found no solution that worked for me yet:

When adding rows to a table from code, the rows are not showing up in the application. There is one row I specified in XML, that one is showing up, but nothing below it.

This is the code, I've added the constructor of my class as well:

private LayoutInflater theInflater;
private LinkedList<View> rows;
private Context thisContext;

public DistanceTableView(LayoutInflater vi, Context context)
{
  theInflater = vi;
  rows = new LinkedList<View>();
  thisContext = context;    
}

public void addRow(LocationMessage locationMsg){
  View messageView = theInflater.inflate(R.layout.homepage, null);
  TableLayout table = (TableLayout)messageView.findViewById(R.id.distanceTable);

  TextView se开发者_StackOverflownderNameTextView = new TextView(thisContext);
  senderNameTextView.setText(locationMsg.getSenderName());

  TableRow tr = new TableRow(thisContext);
  tr.addView(distanceTextView);
  table.addView(tr);
  rows.addFirst(messageView);
}

homepage.xml contains this, I removed some elements and parameters:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout>
    <TabHost>
    <TabWidget />
        <FrameLayout>
        [..]        
            <LinearLayout>          
            [..]
                <TableLayout
                android:id="@+id/distanceTable" 
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:layout_gravity="center"
                android:background="#DDDDDD"
                android:stretchColumns="1" >
                    <TableRow>
                        <TextView
                        android:textColor="#000000"
                        android:text="@string/label_device"
                        android:layout_gravity="center"
                        android:padding="3dip"
                        android:textSize="18sp" />
                        <TextView
                        android:textColor="#000000"
                        android:text="@string/label_distance"
                        android:layout_gravity="center"
                        android:padding="3dip"
                        android:textSize="18sp" />
                        <TextView
                        android:textColor="#000000"
                        android:text="@string/label_time"
                        android:layout_gravity="center"
                        android:padding="3dip"
                        android:textSize="18sp" />
                    </TableRow>
                </TableLayout>
            </LinearLayout>
        </FrameLayout>
    </TabHost>
</LinearLayout>

Unfortunately hierarchyviewer.bat doesn't work for me in order to check if the rows are there but just not visible. In the debugger it looks fine to me.


I think you should call TableLayout.requestLayout() after you've added the new row.

From the docs:

Call this when something has changed which has invalidated the layout of this view. This will schedule a layout pass of the view tree.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜