1

我有一个应用程序,我在其中使用片段在右窗格中显示动态生成的表。如果我注释掉表格的代码以便布局文件中的 ststic 代码显示在右侧窗格中,则此方法有效,但是当我包含表格时,它会将自身插入左侧面板 - 它应该位于右侧的文本下方窗格。从布局文件和插入表格的代码中提取的附件(不能以新用户的身份上传屏幕截图)。我尝试了许多解决方案,并假设表格代码有问题,无论是在布局中还是在 Java 中。

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:padding="50dip"
  android:background="@color/background_color"
  >

<TextView 
    android:id="@+id/display_readings_title"
    style="@style/textstyle.Heading"
    android:layout_below="@+id/logout" 
    android:text="@string/display_readings_title" 
    android:layout_gravity="center"
    android:layout_marginTop="30dip"
    android:layout_marginBottom="10dip"
    android:layout_centerHorizontal="true"
    />

<TextView 
    android:id="@+id/patient_id_text"
    style="@style/textstyle"
    android:text="@string/patient_id_text" 
    android:layout_marginTop="20dip"
    android:layout_marginLeft="10dip"
    android:layout_below="@id/display_readings_title"
    />

    <TextView 
    android:id="@+id/patient_id"
    style="@style/textstyle"
    android:text="" 
    android:layout_marginLeft="10dip"
    android:layout_below="@id/display_readings_title"
    android:layout_toRightOf="@id/patient_id_text"
    android:layout_alignTop="@id/patient_id_text"
        />

     <TextView 
    android:id="@+id/patient_name_text"
    style="@style/textstyle"
    android:text="@string/patient_name_text" 
    android:layout_marginTop="5dip"
    android:layout_marginLeft="10dip"
    android:layout_below="@id/patient_id_text"
    />

    <TextView 
    android:id="@+id/patient_name"
    style="@style/textstyle"
    android:text="" 
    android:layout_marginLeft="10dip"
    android:layout_below="@id/patient_id_text"
    android:layout_toRightOf="@id/patient_name_text"
    android:layout_alignTop="@id/patient_name_text"
        />

<ScrollView android:id="@+id/ScrollPatientReadings"
    android:layout_width="wrap_content" 
    android:fillViewport="true" 
    android:layout_height="wrap_content"
    android:layout_below="@+id/patient_name_text"
    android:layout_marginTop="20dip"

    >   

<TableLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:stretchColumns="0,1,2,3" 
    android:id="@+id/patient_table"
    android:layout_marginLeft="10dip"
    >
</TableLayout>

</ScrollView>
</RelativeLayout>

从 Java 代码中提取

patient_table = (TableLayout) getActivity().findViewById(
                R.id.patient_table);

        // get patient's readings from the database

                db.open();
                createTableTitle();
                Cursor c = db.getPatientReadings(idtext);
                extractValues(c);
                db.close();
            }

    // create title row

        private void createTableTitle() {
            TableRow titlerow;
            TextView tl1, tl2, tl3, tl4;
            titlerow = new TableRow(getActivity());
            titlerow.setPadding(10, 10, 0, 10);

            tl1 = new TextView(getActivity());
            tl1.setTextColor(getActivity().getResources().getColor(R.color.text_color));
            tl1.setTextSize(20);
            tl2 = new TextView(getActivity());
            tl2.setTextColor(getActivity().getResources().getColor(R.color.text_color));
            tl2.setTextSize(20);

            tl3 = new TextView(getActivity());
            tl3.setTextColor(getActivity().getResources().getColor(R.color.text_color));
            tl3.setTextSize(20);

            tl4 = new TextView(getActivity());
            tl4.setTextColor(getActivity().getResources().getColor(R.color.text_color));
            tl4.setTextSize(20);

            tl1.setText("INR");
            tl2.setText("Surface Bleeding");
            tl3.setText("Internal Bleeding");
            tl4.setText("Date");

            titlerow.addView(tl1);
            titlerow.addView(tl2);
            titlerow.addView(tl3);
            titlerow.addView(tl4);

            patient_table.addView(titlerow);

        }

        private void extractValues(Cursor c) {
            if (c.moveToFirst()) {
                do {
                    String inrReading = c.getString(2);
                    String surface_bleeds = c.getString(3);
                    String internal_bleeding = c.getString(4);
                    String currentDateTimeString = c.getString(5);

                    fillPatientTable(inrReading, surface_bleeds, internal_bleeding,
                            currentDateTimeString);
                } while (c.moveToNext());
            }
        }

        // Display in table

        private void fillPatientTable(String inrReading, String surface_bleeds,
                String internal_bleeding, String currentDateTimeString) {

            TableRow row;
            TextView t1, t2, t3, t4;
            row = new TableRow(getActivity());
            row.setPadding(10, 0, 0, 0);

            t1 = new TextView(getActivity());
            t1.setTextColor(getActivity().getResources().getColor(R.color.text_color));
            t1.setTextSize(18);
            t2 = new TextView(getActivity());
            t2.setTextColor(getActivity().getResources().getColor(R.color.text_color));
            t2.setTextSize(18);
            t3 = new TextView(getActivity());
            t3.setTextColor(getActivity().getResources().getColor(R.color.text_color));
            t3.setTextSize(18);
            t4 = new TextView(getActivity());
            t4.setTextColor(getActivity().getResources().getColor(R.color.text_color));
            t4.setTextSize(18);

            t1.setText(inrReading);
            t2.setText(surface_bleeds);
            t3.setText(internal_bleeding);
            t4.setText(currentDateTimeString);

            row.addView(t1);
            row.addView(t2);
            row.addView(t3);
            row.addView(t4);

            patient_table.addView(row);    
4

1 回答 1

1

经过大量搜索并创建了一个并行应用程序后,我发现问题是由于一个愚蠢的错误造成的。将要放入动态数据的视图“患者表”也被另一个片段引用,该片段创建了一个列表以单击触发该表。

于 2012-04-30T12:40:42.237 回答