Android 重用TableRow

Android 重用TableRow,android,Android,为了在填充TableLayout(使用重复数据)时节省时间,我希望重用TableRows。但是,当我尝试重用它们时,会出现以下错误: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first. 我正在将表行存储在ArrayList中。然后将ArrayList存储在哈希表中。这是我填充ArrayL

为了在填充TableLayout(使用重复数据)时节省时间,我希望重用TableRows。但是,当我尝试重用它们时,会出现以下错误:

java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
我正在将表行存储在ArrayList中。然后将ArrayList存储在哈希表中。这是我填充ArrayList和哈希表的方式:

ArrayList<TableRow> 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<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<TableRow> into the hashtable for reuse
 AcmSinglton.rowHash.put(this.cfr, rowsAl);

}else{
// Resuse the TableRows
    this.rowsAl.addAll(tableRowAl);             
}
arraylisttablerowal=AcmSinglton.rowHash.get(this.cfr);
//如果ArrayList为null,则使用TableRows填充ArrayList
if(tableRowAl==null){
NodeList NodeList=(NodeList)xpath.evaluate(this.xpath,xmlSource,xpathcontents.NODESET);

对于(int i=0;i,在第二段代码中,尝试在再次添加视图之前清理tableView。在for块之前放置类似的内容:
tableView.removeAllViews();

Thx-我会尝试并发回-@PhilVallone如果它解决了您的问题,您应该将此标记为答案。
ArrayList<TableRow> al = new ArrayList<TableRow>();
// get the Arraylist 
al = xmlloaded.getRowsAl();
for (int x=0; x < 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);     
}