テーブルの行をコードから置き換えると奇妙な問題が発生しました。
私の XML コードは次のようになります。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/columnheadings"
android:layout_height="wrap_content"
android:layout_width="fill_parent"/>
<ListView
android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:dividerHeight="2px"
/>
...
</LinearLayout>
アクティビティが作成されると、TableRow を TableLayout の "columnheadings" に正常に挿入できます。
table = (TableLayout)findViewById(R.id.columnheadings);
table.removeAllViews();
TableRow tr = new TableRow(this);
TextView tv = new TextView(activity);
tv.setText("asdf");
tr.addView(tv);
table.addView(tr);
table.postInvalidate();
テーブル列の内容 (および幅) は動的に計算されます。
ListView の Adapter 内で更新がある場合は、TableLayout も再描画します。この目的のために、アクティビティへの参照を使用してアダプターを作成しています。
アダプター内から、たとえば列のテキストを正常に変更できます。
私がやろうとしていること(成功せずに):
TableLayout tableLayout = (TableLayout)activity.findViewById(android.app.R.id.columnheadings);
tableLayout.removeAllViews();
TableRow row=new TableRow(activity);
TextView tv = new TextView(activity);
tv.setText("test");
row.addView(tv);
tableLayout.addView(row);
tableLayout.postInvalidate();
残念ながら、現在のテーブル行が削除されるだけです。新しい行は、アダプターから tableLayout に追加されません。
助言がありますか ?