public abstract class ShardAdapter
extends <any>
RecyclerView.Adapter that represents each page as a Shard.
Subclasses only need to implement createShard(int)
and #getItemCount() to have a working adapter.
ViewPager#getOffscreenPageLimit() number of shards will be kept in memory. Otherwise
their state will be saved and the shard destroyed. The current shard will be in the resumed
state and all other shards will be in the started state. You must override
getItemId(int) and containsItem(long) if you want to be able to dynamically
change the contents on a #notifyDataSetChanged().
| Constructor and Description |
|---|
ShardAdapter(Context context) |
ShardAdapter(ShardOwner owner) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
containsItem(long itemId)
Default implementation works for collections that don't add, move, remove items.
|
abstract Shard |
createShard(int position)
Provide a new Shard associated with the specified position.
|
long |
getItemId(int position)
Default implementation works for collections that don't add, move, remove items.
|
void |
onAttachedToRecyclerView(RecyclerView recyclerView) |
void |
onBindViewHolder(ShardViewHolder holder,
int position) |
ShardViewHolder |
onCreateViewHolder(ViewGroup parent,
int viewType) |
void |
onDetachedFromRecyclerView(RecyclerView recyclerView) |
boolean |
onFailedToRecycleView(ShardViewHolder holder) |
void |
onViewAttachedToWindow(ShardViewHolder holder) |
void |
onViewRecycled(ShardViewHolder holder) |
void |
restoreState(Parcelable savedState) |
Parcelable |
saveState() |
void |
setHasStableIds(boolean hasStableIds) |
public ShardAdapter(Context context)
public ShardAdapter(ShardOwner owner)
public final void onAttachedToRecyclerView(RecyclerView recyclerView)
public final void onDetachedFromRecyclerView(RecyclerView recyclerView)
public abstract Shard createShard(int position)
The Shard will be destroyed when it gets too far from the viewport, and its state will be saved. When the item is close to the viewport again, a new Shard will be requested, and a previously saved state will be used to initialize it.
public final ShardViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
public final void onBindViewHolder(ShardViewHolder holder, int position)
public final void onViewAttachedToWindow(ShardViewHolder holder)
public void onViewRecycled(ShardViewHolder holder)
public boolean onFailedToRecycleView(ShardViewHolder holder)
public long getItemId(int position)
When overriding, also override containsItem(long).
If the item is not a part of the collection, return RecyclerView#NO_ID.
position - Adapter positionRecyclerView.Adapter#hasStableIds()public boolean containsItem(long itemId)
When overriding, also override getItemId(int)
public void setHasStableIds(boolean hasStableIds)
public void restoreState(Parcelable savedState)
public Parcelable saveState()