2016-01-21 57 views
0

我試圖在回收視圖中添加部分/頭回收再利用的運行時間查看
,因爲我們要處理部分的東西,在添加部分與動態數組

@Override 
public int getItemViewType(int position) { 
// here your custom logic to choose the view type 
return position == 0 ? section: item; 

}

,但我具有n個數據的陣列列表。所以說第一節可能有10行,因爲第二節可能有2行。所以在這種情況下如何定義節。我知道這是第一節的結尾?並放置第二個

回答

0

迭代每個模型,並記住每個模型項目的前一節名稱。當您找到新的部分名稱時,只需映射索引即可。

在您的適配器返回項數小於數據集。

@Override 
public int getItemCount(){ 
    return mData.size() + mSections.size(); 
} 

始終使用position + 1,因爲你總是領先地位。

無論何時你來到屬於映射索引位置,回款型,並相應地將其綁定:

@Override 
public int getItemViewType(int position) { 
// here your custom logic to choose the view type 
    return isPositionSectionIndex(position) ? VIEW_TYPE_SECTION: VIEW_TYPE_ITEM; 
}