Android TableRow未显示所有文本视图

Android TableRow未显示所有文本视图,android,Android,我正在运行时创建TableRow。我遇到的问题是,我创建了6个文本视图并添加到TableRow中,但由于某些原因,只有3个文本视图出现,前2个和最后一个。我知道将TextView添加到TableRow没有问题,因为如果我注释掉最后两个TextView,第四个仍然会覆盖第三个。因此,我可以添加到此TableRow的列数似乎有一定的限制 你知道我哪里出错了吗 这是我的java public class locationlist extends Activity { /** Called wh

我正在运行时创建TableRow。我遇到的问题是,我创建了6个文本视图并添加到TableRow中,但由于某些原因,只有3个文本视图出现,前2个和最后一个。我知道将TextView添加到TableRow没有问题,因为如果我注释掉最后两个TextView,第四个仍然会覆盖第三个。因此,我可以添加到此TableRow的列数似乎有一定的限制

你知道我哪里出错了吗

这是我的java

public class locationlist extends Activity {
    /** Called when the activity is first created. */
    private locationListDbAdapter mDbHelper;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       setContentView(R.layout.locationlist);
        mDbHelper = new locationListDbAdapter(this);
        mDbHelper.open();

        String id = mDbHelper.fetchRow(1).getString(0);
        String locationText  = mDbHelper.fetchRow(1).getString(1);
        String localCode = mDbHelper.fetchRow(1).getString(2);
        String localService = mDbHelper.fetchRow(1).getString(3);
        String localComments = mDbHelper.fetchRow(1).getString(4);
        String localNextes = mDbHelper.fetchRow(1).getString(5);



        TextView idView = new TextView(this);
        idView.setText(id);
        TextView locationView = new TextView(this);
        locationView.setText(locationText);
        TextView codeView = new TextView(this);
        codeView.setText(localCode);
        TextView serviceView = new TextView(this);
        codeView.setText(localService);
        TextView commentsView = new TextView(this);
        codeView.setText(localComments);
        TextView nextesView = new TextView(this);
        codeView.setText(localNextes);

        TableLayout tl = (TableLayout)findViewById(R.id.tableLayout1);
        TableRow r2 = new TableRow(this);


        r2.addView(idView);
        r2.addView(locationView);
        r2.addView(codeView);
        r2.addView(serviceView);
        r2.addView(commentsView);
        r2.addView(nextesView);
        tl.addView(r2);

        this.setContentView(tl);
这就是我指向的xml文件

<?xml version="1.0" encoding="utf-8"?>

    <TableLayout android:id="@+id/tableLayout1" android:layout_width="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content">
        <TableRow android:layout_height="wrap_content" android:id="@+id/tableRow1" android:layout_width="fill_parent">
            <TextView android:id="@+id/textView11" android:layout_height="wrap_content" android:text="ID" android:layout_width="0dip" android:layout_weight="0.1"></TextView>
            <TextView android:id="@+id/textView1" android:layout_height="wrap_content" android:text="Location" android:layout_width="0dip" android:layout_weight="0.4"></TextView>
            <TextView android:id="@+id/textView2" android:layout_height="wrap_content" android:text="Type" android:layout_width="0dip" android:layout_weight="0.15"></TextView>
            <TextView android:id="@+id/textView3" android:layout_height="wrap_content" android:text="Service" android:layout_width="0dip" android:layout_weight="0.2"></TextView>
            <TextView android:id="@+id/textView4" android:layout_height="wrap_content" android:text="Comments" android:layout_weight="0.3" android:layout_width="0dip"></TextView>
            <TextView android:id="@+id/textView5" android:layout_height="wrap_content" android:text="ES" android:layout_width="0dip" android:layout_weight="0.15"></TextView>
        </TableRow>
            <View
        android:layout_height="2dip"
        android:background="#FF909090" />
    </TableLayout>

为什么有以下几行?将codeView文本视图设置为localCode的文本,然后无明显原因地覆盖三次:

codeView.setText(localCode);
codeView.setText(localService);
codeView.setText(localComments);
codeView.setText(localNextes);
您的serviceView、commentsView和nextesView文本视图都显示为空白,您从未执行过类似操作:

serviceView.setText(localService);
commentsView.setText(localComments);
nextesView.setText(localNextes);

我会临时用测试字符串替换您的数据库内容,以缩小错误范围,看看它是否仍然失败,如果没有,请处理上面提到的内容,再次测试,如果它现在工作,用数据库内容替换临时文本字符串。

哪些是“前2个和最后一个”?第1个是idView,第二个是locationView,下一个是最后一个。这有意义吗?丹尼斯,非常感谢你指出我在重写我已经做过的事情。这就是复制和粘贴的问题所在。有时候,你只能看到树木而看不到森林。