swapAdapter

open fun swapAdapter(@Nullable adapter: RecyclerView.Adapter, removeAndRecycleExistingViews: Boolean)(source)

Swaps the current adapter with the provided one. It is similar to setAdapter but assumes existing adapter and the new adapter uses the same ViewHolder and does not clear the RecycledViewPool.

Note that it still calls onAdapterChanged callbacks.

Parameters

adapter

The new adapter to set, or null to set no adapter.

removeAndRecycleExistingViews

If set to true, RecyclerView will recycle all existing Views. If adapters have stable ids and/or you want to animate the disappearing views, you may prefer to set this to false.

See also