table layout model data for every row with changed contents.

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

table layout model data for every row with changed contents.

Postby faisalloe » Wed Dec 09, 2009 6:20 am

I am having the following xml contents which i want to use inside a table as a row data as many times by changing their data from the java code at run time.

I can get xml resource using "R.layout.tableRow" but when i try to modify the textviews values for one row it is fine but next time i retrive resource again and want to modify the tetviews values it says already used.

I am having a loop in the parent layout oncreate method, every time i get the xml resource try to modify its contents and try to add in tablerow element but that is not working....

when we create customize Listview we use LayoutInflater inflater=getLayoutInflater(); every time we need to crate new listitem but how can i achieve this in table layout.

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.  
  4. android:layout_width="fill_parent"
  5.  
  6. android:layout_height="wrap_content"
  7.  
  8. android:orientation="horizontal"
  9.  
  10. >
  11.  
  12.  
  13.  
  14.         <TextView android:id="@+id/entityName"
  15.  
  16.                android:layout_width="fill_parent"
  17.  
  18.                android:layout_height="wrap_content"
  19.  
  20.                android:layout_weight="1"
  21.  
  22.                android:gravity="center_vertical"
  23.  
  24.                android:textStyle="bold"
  25.  
  26.                android:singleLine="true"  
  27.  
  28.                android:ellipsize="end"
  29.  
  30.                android:text="event/venue"
  31.  
  32.                android:textColor="@color/maroon"
  33.  
  34.                android:textSize="13px" />
  35.  
  36.  
  37.  
  38.         <TextView android:id="@+id/miles"
  39.  
  40.                android:layout_width="fill_parent"
  41.  
  42.                android:layout_height="wrap_content"
  43.  
  44.                android:layout_weight="4"
  45.  
  46.                android:gravity="fill_horizontal"
  47.  
  48.                android:singleLine="true"
  49.  
  50.                android:text="(0.0m)"
  51.  
  52.                android:textColor="@color/gray"
  53.  
  54.                android:textSize="12px"/>
  55.  
  56.  
  57.  
  58.         </LinearLayout>
  59.  
  60.         <ImageView android:id="@+id/resultStarRating"
  61.  
  62.        android:layout_width="wrap_content"
  63.  
  64.        android:layout_height="wrap_content"
  65.  
  66.        android:layout_alignParentTop="true"
  67.  
  68.        android:layout_alignParentBottom="true"
  69.  
  70.        android:layout_marginRight="4px"/>
  71.  
  72.         <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  73.  
  74.        android:layout_width="fill_parent"
  75.  
  76.        android:layout_height="wrap_content"
  77.  
  78.        android:orientation="horizontal"
  79.  
  80.        >
  81.  
  82.         <TextView android:id="@+id/category"
  83.  
  84.                android:layout_width="wrap_content"
  85.  
  86.                android:layout_height="wrap_content"
  87.  
  88.                android:layout_weight="0"
  89.  
  90.                android:gravity="center_vertical"
  91.  
  92.                android:singleLine="true"
  93.  
  94.                android:ellipsize="end"
  95.  
  96.                android:text="category"
  97.  
  98.                android:textColor="@color/shock_red"
  99.  
  100.                android:textSize="12px"
  101.  
  102.                />
  103.  
  104.         <TextView android:id="@+id/singleDayTiming"
  105.  
  106.                android:layout_width="wrap_content"
  107.  
  108.                android:layout_height="wrap_content"
  109.  
  110.                android:layout_weight="0"
  111.  
  112.                android:gravity="center_vertical"
  113.  
  114.                android:singleLine="true"
  115.  
  116.                android:ellipsize="end"  
  117.  
  118.                android:textColor="@color/black"
  119.  
  120.                android:textSize="12px"/>
  121.  
  122.         </LinearLayout>
  123.  
  124.  
  125.  
  126.         <TextView android:id="@+id/venue"
  127.  
  128.                android:layout_width="wrap_content"
  129.  
  130.                android:layout_height="wrap_content"
  131.  
  132.                android:layout_weight="1"
  133.  
  134.                android:gravity="center_vertical"
  135.  
  136.                android:singleLine="true"
  137.  
  138.                android:ellipsize="end"
  139.  
  140.                android:textColor="@color/maroon"
  141.  
  142.                android:textSize="12px"/>
  143.  
  144.         <TextView android:id="@+id/address"
  145.  
  146.                android:layout_width="wrap_content"
  147.  
  148.                android:layout_height="wrap_content"
  149.  
  150.                android:layout_weight="1"
  151.  
  152.                android:gravity="center_vertical"
  153.  
  154.                android:singleLine="true"
  155.  
  156.                android:ellipsize="end"
  157.  
  158.                android:text="address"
  159.  
  160.                android:textColor="@color/gray"
  161.  
  162.                android:textSize="12px"/>
  163.  
  164. </LinearLayout>
Parsed in 0.011 seconds, using GeSHi 1.0.8.4
faisalloe
Developer
Developer
 
Posts: 29
Joined: Wed Nov 04, 2009 5:01 am

Top

Postby faisalloe » Wed Dec 09, 2009 12:00 pm

When i tried the following code it generated exception after 1st execution

java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.



Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. LayoutInflater factory = LayoutInflater.from(this);
  2.  
  3.                  View tableItem = factory.inflate(R.layout.review_item, null);
  4.  
  5.                  for(int a=0;a<5;a++){
  6.  
  7.                          TableRow row = new TableRow(this);
  8.  
  9.                          row.addView(tableItem);
  10.  
  11.                          row.setId(a);
  12.  
  13.                          tableView.addView(row);
  14.  
  15.                  }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
faisalloe
Developer
Developer
 
Posts: 29
Joined: Wed Nov 04, 2009 5:01 am

Use </TableLayout> may help

Postby sanzeiev » Thu Dec 10, 2009 8:03 am

<?xml version="1.0" encoding="utf-8"?>
<TableLayout
android:id="@+id/widget28"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
>

</TableLayout>
Last edited by sanzeiev on Thu Dec 10, 2009 11:10 am, edited 1 time in total.
sanzeiev
Freshman
Freshman
 
Posts: 8
Joined: Wed Jul 22, 2009 6:08 am

Re: Use </TableLayout> may help

Postby faisalloe » Thu Dec 10, 2009 11:04 am

sanzeiev wrote:<?xml version="1.0" encoding="utf-8"?>
<TableLayout
android:id="@+id/widget28"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
>

<TextView android:id="@+id/category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:gravity="center_vertical"
android:singleLine="true"
android:ellipsize="end"
android:text="category"
android:textColor="@color/shock_red"
android:textSize="12px"
/>
<TextView android:id="@+id/singleDayTiming"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:gravity="center_vertical"
android:singleLine="true"
android:ellipsize="end"
android:textColor="@color/black"
android:textSize="12px"/>
</LinearLayout>

<TextView android:id="@+id/venue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical"
android:singleLine="true"
android:ellipsize="end"
android:textColor="@color/maroon"
android:textSize="12px"/>
<TextView android:id="@+id/address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical"
android:singleLine="true"
android:ellipsize="end"
android:text="address"
android:textColor="@color/gray"
android:textSize="12px"/>
</TableLayout>


thats not the desired ans.
faisalloe
Developer
Developer
 
Posts: 29
Joined: Wed Nov 04, 2009 5:01 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Google [Bot] and 6 guests