ConcatAdapter
An Adapter implementation that presents the contents of multiple adapters in sequence.
MyAdapter adapter1 = ...;
AnotherAdapter adapter2 = ...;
ConcatAdapter concatenated = new ConcatAdapter(adapter1, adapter2);
recyclerView.setAdapter(concatenated);
By default, ConcatAdapter isolates view types of nested adapters from each other such that it will change the view type before reporting it back to the RecyclerView to avoid any conflicts between the view types of added adapters. This also means each added adapter will have its own isolated pool of ViewHolders, with no re-use in between added adapters.
If your Adapters share the same view types, and can support sharing ViewHolder s between added adapters, provide an instance of Config where you set isolateViewTypes to false
. A common usage pattern for this is to return the R.layout.<layout_name>
from the getItemViewType method.
When an added adapter calls one of the notify
methods, ConcatAdapter properly offsets values before reporting it back to the RecyclerView. If an adapter calls notifyDataSetChanged, ConcatAdapter also calls notifyDataSetChanged as calling notifyItemRangeChanged will confuse the RecyclerView. You are highly encouraged to to use SortedList or ListAdapter to avoid calling notifyDataSetChanged.
Whether ConcatAdapter should support stable ids is defined in the Config object. Calling setHasStableIds has no effect. See documentation for Config.StableIdMode for details on how to configure ConcatAdapter to use stable ids. By default, it will not use stable ids and sub adapter stable ids will be ignored. Similar to the case above, you are highly encouraged to use ListAdapter, which will automatically calculate the changes in the data set for you so you won't need stable ids.
It is common to find the adapter position of a ViewHolder to handle user action on the ViewHolder. For those cases, instead of calling getAdapterPosition, use getBindingAdapterPosition. If your adapters share ViewHolders, you can use the getBindingAdapter method to find the adapter which last bound that ViewHolder.
Constructors
Types
Functions
position
for the purposes of view recycling.ConcatAdapter
.