AdapterDelegatesManager { public void onBindViewHolder(@NonNull T items, int position, @NonNull RecyclerView.ViewHolder holder, List payloads) { AdapterDelegate<T> delegate = getDelegateForViewType(holder.getItemViewType()); if (delegate == null) { throw new NullPointerException("No delegate found for item at position = " + position + " for viewType = " + holder.getItemViewType()); } delegate.onBindViewHolder(items, position, holder, payloads != null ? payloads : PAYLOADS_EMPTY_LIST); } AdapterDelegatesManager();  AdapterDelegatesManager(@NonNull AdapterDelegate<T>... delegates); AdapterDelegatesManager<T> addDelegate(@NonNull AdapterDelegate<T> delegate); AdapterDelegatesManager<T> addDelegate(int viewType,
                                                  @NonNull AdapterDelegate<T> delegate); AdapterDelegatesManager<T> addDelegate(int viewType, boolean allowReplacingDelegate,
                                                  @NonNull AdapterDelegate<T> delegate); AdapterDelegatesManager<T> removeDelegate(@NonNull AdapterDelegate<T> delegate); AdapterDelegatesManager<T> removeDelegate(int viewType); int getItemViewType(@NonNull T items, int position); @NonNull RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType); void onBindViewHolder(@NonNull T items, int position,
                                 @NonNull RecyclerView.ViewHolder holder, List payloads); void onBindViewHolder(@NonNull T items, int position,
                                 @NonNull RecyclerView.ViewHolder holder); void onViewRecycled(@NonNull RecyclerView.ViewHolder holder); boolean onFailedToRecycleView(@NonNull RecyclerView.ViewHolder holder); void onViewAttachedToWindow(@NonNull RecyclerView.ViewHolder holder); void onViewDetachedFromWindow(@NonNull RecyclerView.ViewHolder holder); AdapterDelegatesManager<T> setFallbackDelegate(
            @Nullable AdapterDelegate<T> fallbackDelegate); int getViewType(@NonNull AdapterDelegate<T> delegate); @Nullable AdapterDelegate<T> getDelegateForViewType(int viewType); @Nullable AdapterDelegate<T> getFallbackDelegate(); static final int FALLBACK_DELEGATE_VIEW_TYPE; }
@Test public void onBindViewHolder() { List<Object> items = Arrays.asList(new Object(), new Object(), new Object()); SpyableAdapterDelegate<List<Object>> d0 = new SpyableAdapterDelegate<>(0); SpyableAdapterDelegate<List<Object>> d1 = new SpyableAdapterDelegate<>(1); SpyableAdapterDelegate<List<Object>> d2 = new SpyableAdapterDelegate<>(2); AdapterDelegatesManager<List<Object>> manager = new AdapterDelegatesManager<>(); manager.addDelegate(d0); manager.addDelegate(d1); manager.addDelegate(d2); manager.onBindViewHolder(items, 0, d0.viewHolder); Assert.assertTrue(d0.onBindViewHolderCalled); Assert.assertFalse(d1.onBindViewHolderCalled); Assert.assertFalse(d2.onBindViewHolderCalled); resetDelegates(d0, d1, d2); manager.onBindViewHolder(items, 1, d1.viewHolder); Assert.assertTrue(d1.onBindViewHolderCalled); Assert.assertFalse(d0.onBindViewHolderCalled); Assert.assertFalse(d2.onBindViewHolderCalled); resetDelegates(d0, d1, d2); manager.onBindViewHolder(items, 2, d2.viewHolder); Assert.assertTrue(d2.onBindViewHolderCalled); Assert.assertFalse(d1.onBindViewHolderCalled); Assert.assertFalse(d0.onBindViewHolderCalled); resetDelegates(d0, d1, d2); }