private void OffsetPositionRecordsForRemove(int positionStart, int itemCount, bool applyToPreLayout) { int positionEnd = positionStart + itemCount; int childCount = mChildHelper.GetChildCount(); for (int i = 0; i < childCount; i++) { FlexibleViewViewHolder holder = mChildHelper.GetChildAt(i); if (holder != null) { if (holder.AdapterPosition >= positionEnd) { holder.OffsetPosition(-itemCount, applyToPreLayout); } else if (holder.AdapterPosition >= positionStart) { holder.FlagRemovedAndOffsetPosition(positionStart - 1, -itemCount, applyToPreLayout); } } } if (positionEnd <= mFocusedItemIndex) { mFocusedItemIndex -= itemCount; } else if (positionStart <= mFocusedItemIndex) { mFocusedItemIndex = positionStart; if (mFocusedItemIndex >= mAdapter.GetItemCount()) { mFocusedItemIndex = mAdapter.GetItemCount() - 1; } } }
public FlexibleViewViewHolder GetViewForPosition(int position) { FlexibleViewAdapter b = mFlexibleView != null?mFlexibleView.GetAdapter() : null; if (b == null) { return(null); } if (position < 0 || position >= b.GetItemCount()) { return(null); } int type = b.GetItemViewType(position); FlexibleViewViewHolder itemView = null; for (int i = 0; i < mAttachedScrap.Count; i++) { if (mAttachedScrap[i].LayoutPosition == position && mAttachedScrap[i].ItemViewType == type) { itemView = mAttachedScrap[i]; break; } } if (itemView == null) { itemView = mRecyclerPool.GetRecycledView(type); if (itemView == null) { itemView = b.OnCreateViewHolder(type); } if (!itemView.IsBound) { b.OnBindViewHolder(itemView, position); itemView.IsBound = true; } itemView.AdapterPosition = position; itemView.ItemViewType = type; } return(itemView); }