Reusing a TableRow
<p>In order to save time when a TableLayout is populated (with repetitive data), I want to reuse TableRows. However when I try to reuse them, I get the following error:</p>

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

<p>I am storing the TableRows in an ArrayList. I then store the ArrayList in a Hashtable. This is how I am populating the ArrayList and Hashtable:</p>

<pre><code>ArrayList&lt;TableRow&gt; tableRowAl = AcmSinglton.rowHash.get(this.cfr);
// if ArrayList is null, populate the ArrayList with the TableRows  
if (tableRowAl == null){

NodeList nodeList = (NodeList) xpath.evaluate(this.xpath, xmlSource, XPathConstants.NODESET);

 for(int i=0; i&lt;nodeList.getLength(); i++){
     TableRow tr = new TableRow(this.activity);
     tr.removeAllViews();
     tr.setId(i);
     TextView tv = new TextView(this.activity);              
     Element chapElement = (Element) nodeList.item(i);
     tv.setText(chapElement.getAttribute(this.attribute));                  
     tr.addView(tv);         
     rowsAl.add(tr);   
  }
 // put the ArrayList&lt;TableRow&gt; into the hashtable for reuse
 AcmSinglton.rowHash.put(this.cfr, rowsAl);

}else{
// Resuse the TableRows
    this.rowsAl.addAll(tableRowAl);             
}
</code></pre>

<p>When I try to add the TableRow to the tableLayout, I get the error:</p>

<pre><code>ArrayList&lt;TableRow&gt; al = new ArrayList&lt;TableRow&gt;();
// get the Arraylist 
al = xmlloaded.getRowsAl();
for (int x=0; x &lt; al.size(); x++){
    TableRow tableRow = new TableRow(this);
    tableRow = al.get(x);
    View child = tableRow.getChildAt(0);
    final TextView tx = (TextView)child;
    // I get the error here when I try to add the TableRow  
    tableView.addView(tableRow);     
}
</code></pre>

<p>Thanks for the help.</p>
