T
- type of RealmModel
stored in the adapter.S
- type of RecyclerView.ViewHolder used in the adapter.public abstract class RealmRecyclerViewAdapter<T extends RealmModel,S extends android.support.v7.widget.RecyclerView.ViewHolder>
extends android.support.v7.widget.RecyclerView.Adapter<S>
This adapter will automatically handle any updates to its data and call notifyDataSetChanged()
, notifyItemInserted()
, notifyItemRemoved()
or notifyItemRangeChanged(
as appropriate.
The RealmAdapter will stop receiving updates if the Realm instance providing the OrderedRealmCollection
is closed.
If the adapter contains Realm model classes with a primary key that is either an int
or a long
, call setHasStableIds(true)
in the constructor and override RecyclerView.Adapter.getItemId(int)
as described by the Javadoc in that method.
RecyclerView.Adapter#setHasStableIds(boolean)
, RecyclerView.Adapter#getItemId(int)
Constructor and Description |
---|
RealmRecyclerViewAdapter(OrderedRealmCollection<T> data, boolean autoUpdate) This is equivalent to RealmRecyclerViewAdapter(data, autoUpdate, true) . |
RealmRecyclerViewAdapter(OrderedRealmCollection<T> data, boolean autoUpdate, boolean updateOnModification) |
Modifier and Type | Method and Description |
---|---|
OrderedRealmCollection<T> | getData() Returns data associated with this adapter. |
T | getItem(int index) Returns the item associated with the specified position. |
int | getItemCount() |
void | onAttachedToRecyclerView(android.support.v7.widget.RecyclerView recyclerView) |
void | onDetachedFromRecyclerView(android.support.v7.widget.RecyclerView recyclerView) |
void | updateData(OrderedRealmCollection<T> data) Updates the data associated to the Adapter. |
bindViewHolder, createViewHolder, getItemId, getItemViewType, hasObservers, hasStableIds, notifyDataSetChanged, notifyItemChanged, notifyItemChanged, notifyItemInserted, notifyItemMoved, notifyItemRangeChanged, notifyItemRangeChanged, notifyItemRangeInserted, notifyItemRangeRemoved, notifyItemRemoved, onBindViewHolder, onBindViewHolder, onCreateViewHolder, onFailedToRecycleView, onViewAttachedToWindow, onViewDetachedFromWindow, onViewRecycled, registerAdapterDataObserver, setHasStableIds, unregisterAdapterDataObserver
public RealmRecyclerViewAdapter(@Nullable OrderedRealmCollection<T> data, boolean autoUpdate)
RealmRecyclerViewAdapter(data, autoUpdate, true)
.public RealmRecyclerViewAdapter(@Nullable OrderedRealmCollection<T> data, boolean autoUpdate, boolean updateOnModification)
data
- collection data to be used by this adapter.autoUpdate
- when it is false
, the adapter won't be automatically updated when collection data changes.updateOnModification
- when it is true
, this adapter will be updated when deletions, insertions or modifications happen to the collection data. When it is false
, only deletions and insertions will trigger the updates. This param will be ignored if autoUpdate
is false
.public void onAttachedToRecyclerView(android.support.v7.widget.RecyclerView recyclerView)
onAttachedToRecyclerView
in class android.support.v7.widget.RecyclerView.Adapter<S extends android.support.v7.widget.RecyclerView.ViewHolder>
public void onDetachedFromRecyclerView(android.support.v7.widget.RecyclerView recyclerView)
onDetachedFromRecyclerView
in class android.support.v7.widget.RecyclerView.Adapter<S extends android.support.v7.widget.RecyclerView.ViewHolder>
public int getItemCount()
getItemCount
in class android.support.v7.widget.RecyclerView.Adapter<S extends android.support.v7.widget.RecyclerView.ViewHolder>
@Nullable public T getItem(int index)
null
if provided Realm instance by OrderedRealmCollection
is closed.index
- index of the item.null
if adapter data is not valid.@Nullable public OrderedRealmCollection<T> getData()
public void updateData(@Nullable OrderedRealmCollection<T> data)
data
- the new OrderedRealmCollection
to display.