2016-09-16 9 views
1

私は、次の方法テーブルのインデックス値を取得する方法は?

if(tbl.getParent() instanceof Body) 
{ 
    Body body = (Body) tbl.getParent(); 
    int tIndex = body.getContent().indexOf(tbl); 
    body.getContent().remove(tbl); 
} 

を使用してテーブルのインデックス値を取得しようとしましたが、別の方法がcontentAccessor

if(tbl.getParent() instanceof ContentAccessor) 
{ 
    ContentAccessor ca = (ContentAccessor) tbl.getParent(); 
    int tIndex = ca.getContent().indexOf(tbl); 
    ca.getContent().remove(tbl); 
} 

を使用して代わりの私が取得しています実際のインデックス値を取得している-1 tIndexとして。また、それは親からtbl(ca.getContent()。remove(tbl);)を削除していません。

Tblのインデックス値を取得する他の方法はありますか?

答えて

1
ContentAccessor ca = (ContentAccessor) tbl.getParent(); 
    int tIndex = getIndex(ca.getContent(), tbl); 
    if(tIndex != 98761){ 
    //do whatever you want to 
    } 

    private static int getIndex(List<Object> theList, Object bm) 
    { 
     for (Object ox : theList) 
     { 
     if (XmlUtils.unwrap(ox).equals(bm)) 
     { 
      int o = theList.indexOf(ox); 
      return o; 

     } 
     } 
    return 98761; 

    } 

私の場合、tIndexはそれほど多くのnum(98761)には触れません。あなたが安全でないと感じたら、戻り値を増やしてください。

関連する問題