Java 如何在Android中使用带充气器的xml从ArrayList动态填充TableLayout

Java 如何在Android中使用带充气器的xml从ArrayList动态填充TableLayout,java,android,android-tablelayout,Java,Android,Android Tablelayout,我试图在创建类时动态填充TableLayout,方法是膨胀TableRow xml布局,以模拟创建“报告”。我应该澄清一下,这是在安卓工作室 我的代码似乎运行得很好,找到TableRow并将其添加到TableLayout中,但当我在模拟器上运行应用程序时,它没有显示任何内容(表明它实际上没有向布局添加任何内容)。我已经尝试过调试,甚至在类中编写变量状态的日志,但一切似乎都很好,只是没有显示在应用程序中 以下是我的TableRow xml代码: <?xml version="1.0" enc

我试图在创建类时动态填充TableLayout,方法是膨胀TableRow xml布局,以模拟创建“报告”。我应该澄清一下,这是在安卓工作室

我的代码似乎运行得很好,找到TableRow并将其添加到TableLayout中,但当我在模拟器上运行应用程序时,它没有显示任何内容(表明它实际上没有向布局添加任何内容)。我已经尝试过调试,甚至在类中编写变量状态的日志,但一切似乎都很好,只是没有显示在应用程序中

以下是我的TableRow xml代码:

<?xml version="1.0" encoding="utf-8"?>
<TableRow
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="8dp"
    android:background="@color/colorWhite">

<TextView
    android:id="@+id/rowPatientVerWhen"
    android:layout_width="133dp"
    android:layout_height="match_parent"
    android:gravity="left|center_vertical"
    android:textIsSelectable="false"
    android:clickable="false"
    android:focusable="false"
    android:focusableInTouchMode="false"
    android:background="@drawable/my_border"
    android:textColor="@color/colorBlack"
    android:textSize="18sp"/>

<TextView
    android:id="@+id/rowPatientTestName"
    android:layout_width="135dp"
    android:layout_height="match_parent"
    android:gravity="left|center_vertical"
    android:textIsSelectable="false"
    android:clickable="false"
    android:focusable="false"
    android:focusableInTouchMode="false"
    android:background="@drawable/my_border"
    android:textColor="@color/colorBlack"
    android:textSize="18sp"/>

<TextView
    android:id="@+id/rowPatientResult"
    android:layout_width="126dp"
    android:layout_height="match_parent"
    android:gravity="left|center_vertical"
    android:textIsSelectable="false"
    android:clickable="false"
    android:focusable="false"
    android:focusableInTouchMode="false"
    android:background="@drawable/my_border"
    android:textColor="@color/colorBlack"
    android:textSize="18sp"/>

</TableRow>
<TableLayout
    android:id="@+id/patientTestsTableLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_constraintTop_toBottomOf="@id/patientResultsLabelsLayout"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent">

</TableLayout>

下面是我的TableLayout xml代码:

<?xml version="1.0" encoding="utf-8"?>
<TableRow
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="8dp"
    android:background="@color/colorWhite">

<TextView
    android:id="@+id/rowPatientVerWhen"
    android:layout_width="133dp"
    android:layout_height="match_parent"
    android:gravity="left|center_vertical"
    android:textIsSelectable="false"
    android:clickable="false"
    android:focusable="false"
    android:focusableInTouchMode="false"
    android:background="@drawable/my_border"
    android:textColor="@color/colorBlack"
    android:textSize="18sp"/>

<TextView
    android:id="@+id/rowPatientTestName"
    android:layout_width="135dp"
    android:layout_height="match_parent"
    android:gravity="left|center_vertical"
    android:textIsSelectable="false"
    android:clickable="false"
    android:focusable="false"
    android:focusableInTouchMode="false"
    android:background="@drawable/my_border"
    android:textColor="@color/colorBlack"
    android:textSize="18sp"/>

<TextView
    android:id="@+id/rowPatientResult"
    android:layout_width="126dp"
    android:layout_height="match_parent"
    android:gravity="left|center_vertical"
    android:textIsSelectable="false"
    android:clickable="false"
    android:focusable="false"
    android:focusableInTouchMode="false"
    android:background="@drawable/my_border"
    android:textColor="@color/colorBlack"
    android:textSize="18sp"/>

</TableRow>
<TableLayout
    android:id="@+id/patientTestsTableLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_constraintTop_toBottomOf="@id/patientResultsLabelsLayout"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent">

</TableLayout>

下面是调用onCreate方法时我在类中用来填充TableLayout的内容:

TableLayout table =(TableLayout)PatientResultsReportActivity.this.findViewById(R.id.patientTestsTableLayout);
    fillPatientTests(DBCustomOperation.getPatientResults(PatientResultsReportActivity.this,patient),table);

    this.setTitle(patient.getName() + " Results Report");
}

private void fillPatientTests(ArrayList<Result> results, TableLayout table) {
    if(results.size() == 0) {
        TableRow row = (TableRow) LayoutInflater.from(PatientResultsReportActivity.this).inflate(R.layout.patient_test_row_layout, null);
        ((TextView) row.findViewById(R.id.rowPatientVerWhen)).setText("N/A");
        ((TextView) row.findViewById(R.id.rowPatientTestName)).setText("N/A");
        ((TextView) row.findViewById(R.id.rowPatientResult)).setText("N/A");
        table.addView(row);
    } else {
        for(int i = 0; i < results.size(); i++) {
            TableRow row = (TableRow) LayoutInflater.from(PatientResultsReportActivity.this).inflate(R.layout.patient_test_row_layout, null);
            ((TextView) row.findViewById(R.id.rowPatientVerWhen)).setText(results.get(i).getResultWhen());
            ((TextView) row.findViewById(R.id.rowPatientTestName)).setText(results.get(i).getTestName());
            ((TextView) row.findViewById(R.id.rowPatientResult)).setText(results.get(i).getResult());
            table.addView(row);
        }
    }
    table.requestLayout();
}
TableLayout table=(TableLayout)patientsresultsreportivity.this.findviewbyd(R.id.patientstablelayout);
fillPatientTests(DBCustomOperation.getPatientResults(PatientResultsReportActivity.this,patient),表);
this.setTitle(patient.getName()+“结果报告”);
}
专用空心填充集(ArrayList结果,TableLayout表){
如果(results.size()==0){
TableRow row=(TableRow)LayoutFlater.from(PatientResultsReportActivity.this)。充气(R.layout.patient\u test\u row\u layout,null);
((TextView)row.findViewById(R.id.rowPatientVerWhen)).setText(“不适用”);
((TextView)row.findViewById(R.id.rowPatientTestName)).setText(“不适用”);
((TextView)row.findViewById(R.id.rowPatientResult)).setText(“不适用”);
表.addView(行);
}否则{
对于(int i=0;i
关于我可能遗漏的东西有什么想法吗?在生成或运行期间,我没有收到任何错误消息