0
我想通過編程方式填充在佈局xml文件中定義的表格。我已經定義了Table,其中單行定義了其標題,並設置了所有屬性。現在我想知道一種方式,這樣我就可以用新內容在表格中複製該表頭。如何使用佈局XML文件中定義的視圖作爲模板創建視圖編程方式
我試着用inflator充氣(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>
它的工作。 我曾嘗試使用相同的步驟,但我認爲我有錯誤的充氣部分。我試着膨脹上面的XML文件的子視圖(TableRow),這一定是它失敗的原因。但是現在我猜想膨脹的東西在整個佈局XML文件上都不起作用。我想知道這種功能的原因是什麼。 – Amit 2010-03-02 05:12:42