現在、既存のテーブルに行を追加するアプリケーションを作成しています。コードは次のようになります。私はtabwidget内部でframeLayoutのthatsの内側のLinearLayoutのthatsの内側にありますテーブルのレイアウトを持っているXMLでAndroidでTableRowにビューを追加するとIllegalStateExceptionが発生する
TextView exampleTextView = (TextView) messageView.findViewById(R.id.exampleLabel);
exampleTextView.setText(locationMsg.getMessageContent());
TableRow tr = (TableRow) messageView.findViewById(R.id.tableRow);
tr.addView(exampleTextView);
table.addView(tr);
、それは次のようになります。
<TableLayout
android:id="@+id/distanceTable"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:background="#DDDDDD"
android:stretchColumns="1" >
<TableRow>
<TextView
android:textColor="#000000"
android:text="@string/label_device"
android:layout_gravity="center"
android:padding="3dip"
android:textSize="18sp" />
<TextView
android:textColor="#000000"
android:text="@string/label_distance"
android:layout_gravity="center"
android:padding="3dip"
android:textSize="18sp" />
<TextView
android:textColor="#000000"
android:text="@string/label_time"
android:layout_gravity="center"
android:padding="3dip"
android:textSize="18sp" />
</TableRow>
<TableRow android:id="@+id/tableRow" >
<TextView
android:id="@+id/exampleLabel"
android:textColor="#000000"
android:layout_gravity="center"
android:padding="3dip"
android:textSize="18sp" />
<TextView
android:id="@+id/anotherExampleLabel"
android:textColor="#000000"
android:layout_gravity="center"
android:padding="3dip"
android:textSize="18sp" />
<TextView
android:id="@+id/someOtherLabel"
android:textColor="#000000"
android:layout_gravity="center"
android:padding="3dip"
android:textSize="18sp" />
</TableRow>
</TableLayout>
たものを作成しますラベルは正常に動作しますが、テキストを行に追加するときにアプリケーションがクラッシュし、「IllegalStateException」というメッセージが表示されます。
指定した子にはすでに親があります。最初に子の親に対してremoveView() を呼び出す必要があります。
私はかなりそれを得ることはありません。 thisのようなチュートリアルを見ると、最初に削除する必要はありません。 どうして私は間違っているのですか?
私はコードで定義するときにエラーに遭遇したので、すでにXMLでラベルを定義しようとしました。新しい質問でそのエラーを指定します。ありがとう! – Lars