@Override public void destroyItem(ViewGroup collection, int position, Object object) { EfficientViewHolder viewHolder = (EfficientViewHolder) object; collection.removeView(viewHolder.getView()); onViewDetachedFromWindow(viewHolder); int viewType = getItemViewType(position); List<EfficientViewHolder> viewHolders = mRecycleViewHolders.get(viewType); if (viewHolders == null) { viewHolders = new ArrayList<>(); } mRecycleViewHolders.put(viewType, viewHolders); viewHolders.add(viewHolder); }
@Override public Object instantiateItem(ViewGroup collection, int position) { int viewType = getItemViewType(position); List<EfficientViewHolder> viewHolders = mRecycleViewHolders.get(viewType); EfficientViewHolder viewHolder; if (viewHolders == null || viewHolders.isEmpty()) { viewHolder = onCreateViewHolder(collection, viewType); } else { viewHolder = viewHolders.remove(0); onViewRecycled(viewHolder); } onBindViewHolder(viewHolder, position); collection.addView(viewHolder.getView(), 0); onViewAttachedToWindow(viewHolder); return viewHolder; }