Android 添加到表中的行未显示

Android 添加到表中的行未显示,android,android-tablelayout,Android,Android Tablelayout,以前有人问过这个问题,但我还没有找到适合我的解决方案: 从代码向表中添加行时,这些行不会显示在应用程序中。我在XML中指定了一行,这一行显示出来了,但下面什么也没有 这是代码,我还添加了类的构造函数: private LayoutInflater theInflater; private LinkedList<View> rows; private Context thisContext; public DistanceTableView(LayoutInflater vi, Co

以前有人问过这个问题,但我还没有找到适合我的解决方案:

从代码向表中添加行时,这些行不会显示在应用程序中。我在XML中指定了一行,这一行显示出来了,但下面什么也没有

这是代码,我还添加了类的构造函数:

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 senderNameTextView = new TextView(thisContext);
  senderNameTextView.setText(locationMsg.getSenderName());

  TableRow tr = new TableRow(thisContext);
  tr.addView(distanceTextView);
  table.addView(tr);
  rows.addFirst(messageView);
}
private LayoutInflater;
私有链接列表行;
私人语境;
公共距离表视图(LayoutFlater vi,上下文)
{
松果体=vi;
行=新链接列表();
这个上下文=上下文;
}
public void addRow(LocationMessage locationMsg){
View messageView=theInflater.flate(R.layout.homepage,null);
TableLayout table=(TableLayout)messageView.findviewbyd(R.id.distanceTable);
TextView senderNameTextView=新的TextView(此上下文);
senderNameTextView.setText(locationMsg.getSenderName());
TableRow tr=新的TableRow(thisContext);
tr.addView(距离文本视图);
表1.addView(tr);
rows.addFirst(messageView);
}
homepage.xml包含此内容,我删除了一些元素和参数:

<?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>

[..]        
[..]

不幸的是,hierarchyviewer.bat不适用于我检查行是否存在,但只是不可见。在调试器中,它看起来很好。

我认为您应该在添加新行后调用TableLayout.requestLayout()

从:

当某些事情发生变化时,请拨打此电话 这已经使布局失效 这是一种观点。这将安排一个布局 视图树的过程


不幸的是,这没有帮助。您的
活动中是否有
addRow()
方法?什么是
-它是如何初始化的,以及
addFirst()
做什么?
thisContext
是如何初始化的?我在上面的问题中扩展了代码部分<代码>行
是视图的
链接列表
。我已经添加了初始化这些东西的构造函数
addRow()
位于扩展另一个类的类中,该类扩展了
MapActivity