@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; }
@Override public void onBindViewHolder(EfficientViewHolder viewHolder, int position) { T object = mBaseAdapter.get(position); viewHolder.onBindView(object, position); mBaseAdapter.setClickListenerOnView(this, viewHolder); mBaseAdapter.setLongClickListenerOnView(this, viewHolder); }
@Override public void onViewDetachedFromWindow(EfficientViewHolder holder) { holder.onViewDetachedFromWindow(); }
@Override public void onViewAttachedToWindow(EfficientViewHolder holder) { holder.onViewAttachedToWindow(); }
@Override public void onViewRecycled(EfficientViewHolder holder) { holder.onViewRecycled(); }