views:

51

answers:

1

I want to populate a table, defined in layout xml file through the programmatic way. I have define Table with a single row defining its header, with all the attributes set. Now i want to know a way so that i can just replicate that header row in the table with new content.

I tried using inflator inflate(int,view) method, but at runtime it showed up with error.

Here is the XML code for the layout file defining the table

<?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>
A: 

Step #1: Pull that row out into a separate layout file

Step #2: Inflate that layout file whenever you need a row

Step #3: Call addView() on the TableLayout to add the inflated row

CommonsWare
it Worked.I had tried using the same steps, but i think i had got wrong with inflate part. I tried Inflating subview(TableRow) of the above XML file and that must be the reason that it was failing. But now i guess the inflating thing works on whole layout XML file not part of it. I wonder what could be the reason for such sort of functionality..
Amit