2012-07-17 4 views
0

TextView 및 TableLayout이 포함 된 LinearLayout이 있습니다. 여기 내 XML 파일의 형식입니다.LinearLayout 내부의 TableLayout을 지우면 TextView 헤더가 제거됩니다.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
> 
<TextView 
     android:id="@+id/txtHeader" 
     android:layout_width="match_parent" 
     android:text="Header" /> 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:stretchColumns="1"> 
    <TableRow> 
     <!-- Column 1 --> 
     <TextView 
     android:id="@+id/row1Item1" 
     android:text="Column1" /> 
     <!-- Column 2 --> 
     <TextView 
     android:id="@+id/row1Item2" 
     android:text="Column2" /> 
    </TableRow> 
</TableLayout> 
</LinearLayout> 

동적으로 테이블에 행을 추가하려고합니다. 매번 업데이트가 생기고 테이블을 지우고 새로운 정보 (행 수는 변수)를 작성해야합니다. 그래서 나는 업데이트해야 할 때마다 첫 번째 단계로 테이블을 정리하려고 노력하고 있습니다.

ll = (LinearLayout)findViewById(R.id.wlayout); 
    tb = (TableLayout)findViewById(R.id.wtable); 

private void on Update(){ 
tb.removeAllViewsInLayout(); 

Create table dynamically.. 
} 

하지만 내 텍스트 헤더도 제거됩니다. 나는 또한 ll.removeView (tb)를 시도했다. 여기서 ll은 LinearLayout이다. 아무도 나를 도와주세요. 나는 안드로이드가 처음이다. 고맙습니다.

+0

내가 말을 무슨 뜻인지 이해한다면? –

답변

0

당신은 TableLayout 태그에 id를 부여하지 않았습니다. id를주고 지우려고하십시오.

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="[email protected]/wtable" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:stretchColumns="1"> 
    <TableRow> 
     <!-- Column 1 --> 
     <TextView 
     android:id="@+id/row1Item1" 
     android:text="Column1" /> 
     <!-- Column 2 --> 
     <TextView 
     android:id="@+id/row1Item2" 
     android:text="Column2" /> 
    </TableRow> 
</TableLayout> 

그리고이 시도 ..

tb = (TableLayout)findViewById(R.id.wtable); 
tb.removeAllViewsInLayout(); 
+0

오, 정말 미안해. 내 책상에 이드를 줬어. 난 그냥 내 XML 형식을 보여 주려고했다. 그래서 나는 그것을 임시로 여기에서 제거했다. –

+0

헤더 행도 삭제됩니다. 헤더를 유지하고 동적으로 생성 된 행을 삭제하는 방법은 없습니다. –

관련 문제