1

プログラムによる方法で、レイアウト xml ファイルで定義されたテーブルにデータを入力したいと考えています。すべての属性が設定されたヘッダーを定義する単一行でテーブルを定義しました。今、テーブルのヘッダー行を新しいコンテンツで複製できる方法を知りたいです。

インフレータの inflate(int,view) メソッドを使用してみましたが、実行時にエラーが表示されました。

テーブルを定義するレイアウト ファイルの XML コードを次に示します。

<?xml version="1.0" encoding="utf-8"?>
<TableLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:stretchColumns="0,1,2"
 android:id="@+id/tLayout"
 > 
 <TableRow
  android:layout_width="fill_parent"
  android:id="@+id/tRow">
  <TextView
   android:id="@+id/name"
   android:padding="3dip"
   android:gravity="left"
   android:text="Name"
   />
  <TextView
   android:id="@+id/address"
   android:padding="3dip"
   android:gravity="left"
   android:text="Address"
   />
  <TextView
   android:id="@+id/age"
   android:padding="3dip"
   android:gravity="left"
   android:text="Age"
   />
 </TableRow>
</TableLayout>
4

1 に答える 1

1

ステップ #1: その行を別のレイアウト ファイルに引き出します

ステップ #2: 行が必要なときはいつでもそのレイアウト ファイルをインフレートする

ステップ #3: を呼び出しaddView()TableLayout、膨張した行を追加します

于 2010-02-28T11:52:45.090 に答える