화면에 2 개의 개별 테이블을 표시하고 있습니다. 첫 번째 테이블을 표시하는 데 문제가 없습니다. TableLayout을 second_table, TableRow tableRow5 참조 는 텍스트 필드 (들) textView51, textView52, textView53java.lang.IllegalStateException : 지정된 자식에 이미 부모가 있습니다. 먼저 아이의 부모에서 removeView()를 호출해야합니다.
TextField의 기본적 열이다. 세 개의 열은 이름, 성, 나이를 표시합니다. 서버에서 가져온 값을 동적으로 설정해야합니다.
다음과 같은 예외가 있습니다. java.lang.IllegalStateException : 지정된 자식에 이미 부모가 있습니다. 먼저 부모의 부모에 대해 removeView()를 호출해야합니다. 나도 몇 가지 변화를 시도
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.employee_details);
TableLayout tableLay = (TableLayout) findViewById(R.id.second_table);
TableRow tableRow = (TableRow) findViewById(R.id.tableRow5);
TextView fNameTxtView = (TextView) findViewById(R.id.textView51);
TextView lNameTxtView = (TextView) findViewById(R.id.textView52);
TextView ageTxtView = (TextView) findViewById(R.id.textView53);
for(int count = 0; count < tempArrList.size() ; count++){
fNameTxtView.setText(tempArrList.get(temp.get(0)));
lNameTxtView.setText(tempArrList.get(temp.get(1)));
ageTxtView.setText(tempArrList.get(temp.get(2)));
tableRow.addView(fNameTxtView);
tableRow.addView(lNameTxtView);
tableRow.addView(ageTxtView);
tableLay.addView(tableRow); // Add the new row to our tableLayout
}
}
하지만, 문제를 해결할 수없는 :
나는 다음 코드 줄을 사용하여 두 번째 테이블을 채우기입니다. 제안 사항을 환영합니다.
레이아웃 XML은 다음과 같습니다 삽입
tableRow.addView(fNameTxtView);
tableRow.addView(lNameTxtView);
tableRow.addView(ageTxtView);
tableLay.addView(tableRow);
: employee_details.xml 같은 TextView
및 TableRow
객체와 당신이 모든 시간을 사용하여 for
문에서
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<include android:id="@+id/header" layout="@layout/activity_header" />
<RelativeLayout android:id="@+id/RelativeLayout1"
android:background="@drawable/footerbg" android:layout_height="wrap_content"
android:layout_width="fill_parent" android:layout_alignParentBottom="true"
android:gravity="center">
<Button android:layout_alignParentTop="true"
android:layout_height="50dp" android:layout_width="150dp" android:id="@+id/btn_done"></Button>
</RelativeLayout>
<ScrollView android:id="@+id/scrollView01"
android:layout_above="@id/RelativeLayout1" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_below="@+id/header">
<LinearLayout android:id="@+id/linear"
android:orientation="vertical" android:layout_gravity="center_horizontal"
android:layout_width="match_parent" android:layout_height="match_parent">
<TextView android:id="@+id/hello_TxtView"
android:layout_width="wrap_content" android:layout_height="wrap_content">
</TextView>
<TableLayout android:id="@+id/first_table"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:background="@drawable/table_shape">
<TableRow android:id="@+id/tableRow1" android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView android:id="@+id/textView11"
android:layout_width="fill_parent" android:layout_height="match_parent">
</TextView>
<TextView android:id="@+id/textView12"
android:layout_width="fill_parent" android:layout_height="wrap_content">
</TextView>
</TableRow>
</TableLayout>
<TableLayout android:id="@+id/second_table"
android:layout_width="match_parent" android:layout_height="match_parent">
<TableRow android:id="@+id/tableRow4" android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView android:id="@+id/textView41"
android:layout_width="match_parent" android:layout_height="wrap_content">
</TextView>
<TextView android:id="@+id/textView42"
android:layout_width="fill_parent" android:layout_height="wrap_content">
</TextView>
<TextView android:id="@+id/textView43"
android:layout_width="fill_parent" android:layout_height="wrap_content">
</TextView>
</TableRow>
<TableRow android:id="@+id/tableRow5" android:layout_width="match_parent"
android:layout_height="wrap_content" android:background="#f6f7fc">
<TextView android:id="@+id/textView51"
android:layout_width="match_parent" android:layout_height="wrap_content">
</TextView>
<TextView android:id="@+id/textView52"
android:layout_width="match_parent" android:layout_height="wrap_content">
</TextView>
<TextView android:id="@+id/textView53"
android:layout_width="match_parent" android:layout_height="wrap_content">
</TextView>
</TableRow>
</TableLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>