FragmentStateAdapter
abstract class FragmentStateAdapter : RecyclerView.Adapter<FragmentViewHolder!>, StatefulAdapter
kotlin.Any | ||
↳ | androidx.recyclerview.widget.RecyclerView.Adapter<androidx.viewpager2.adapter.FragmentViewHolder> | |
↳ | androidx.viewpager2.adapter.FragmentStateAdapter |
Similar in behavior to FragmentStatePagerAdapter
Lifecycle within RecyclerView
:
RecyclerView.ViewHolder
initially an emptyFrameLayout
, serves as a re-usable container for aFragment
in later stages.- RecyclerView.Adapter#onBindViewHolder we ask for a
Fragment
for the position. If we already have the fragment, or have previously saved its state, we use those. - RecyclerView.Adapter#onAttachedToWindow we attach the
Fragment
to a container. RecyclerView.Adapter#onViewRecycled
we remove, save state, destroy theFragment
.
Summary
Nested classes | |
---|---|
abstract |
Callback interface for listening to fragment lifecycle changes that happen inside the adapter. |
Public constructors | |
---|---|
<init>(@NonNull fragmentActivity: FragmentActivity) |
|
<init>(@NonNull fragmentManager: FragmentManager, @NonNull lifecycle: Lifecycle) |
Public methods | |
---|---|
open Boolean |
containsItem(itemId: Long) Default implementation works for collections that don't add, move, remove items. |
abstract Fragment |
createFragment(position: Int) Provide a new Fragment associated with the specified position. |
open Long |
Default implementation works for collections that don't add, move, remove items. |
open Unit |
onAttachedToRecyclerView(@NonNull recyclerView: RecyclerView) |
Unit |
onBindViewHolder(@NonNull holder: FragmentViewHolder, position: Int) |
FragmentViewHolder |
onCreateViewHolder(@NonNull parent: ViewGroup, viewType: Int) |
open Unit |
onDetachedFromRecyclerView(@NonNull recyclerView: RecyclerView) |
Boolean |
onFailedToRecycleView(@NonNull holder: FragmentViewHolder) |
Unit |
onViewAttachedToWindow(@NonNull holder: FragmentViewHolder) |
Unit |
onViewRecycled(@NonNull holder: FragmentViewHolder) |
open Unit |
registerFragmentTransactionCallback(@NonNull callback: FragmentStateAdapter.FragmentTransactionCallback) Registers a |
Unit |
restoreState(@NonNull savedState: Parcelable) |
Parcelable | |
Unit |
setHasStableIds(hasStableIds: Boolean) |
open Unit |
unregisterFragmentTransactionCallback(@NonNull callback: FragmentStateAdapter.FragmentTransactionCallback) Unregisters a |
Inherited functions | |
---|---|