2012-04-25 5 views
1

오른쪽 분할 창에서 동적으로 생성 된 테이블을 표시하기 위해 조각을 사용하는 앱이 있습니다. 레이아웃 파일의 ststic 코드가 오른쪽 창에 표시되도록 테이블 코드를 주석 처리하면 작동하지만, 테이블을 포함 시키면 왼쪽 패널에 그 자체가 삽입됩니다. 오른쪽 창. 레이아웃 파일에서 첨부 된 추출물 및 테이블 삽입 코드 (새 사용자로 스크린 샷을 업로드 할 수 없음). 수많은 솔루션을 시도했으며 레이아웃이나 Java에서 테이블 코드에 문제가 있다고 가정합니다.Android Fragment table display

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

많이 검색 한 후 자바 코드

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);  

답변

1

에서 추출 인해 바보 같은 실수로 내가 문제가 것을 발견했다 병렬 응용 프로그램을 작성. 동적 데이터를 넣을 뷰 'patient_table'도 테이블을 트리거 한 목록을 클릭하는 목록을 만든 다른 조각에 의해 참조되었습니다.