Item - Type of the item presented within a data set of a subclass of this SimpleRecyclerAdapter.VH - Type of the view holder used within a subclass of this SimpleRecyclerAdapter.public abstract class SimpleRecyclerAdapter<Item,VH extends RecyclerView.ViewHolder> extends BaseRecyclerAdapter<Item,VH> implements ItemsAdapter<Item>
BaseRecyclerAdapter implementation which specifies simple API for data set management
of items. This adapter supports changing of the current data set via changeItems(List)
and obtaining an item for a desired position via getItem(int). All items attached to the
adapter may be obtained via getItems().
In the simplest implementation case of this adapter, only BaseRecyclerAdapter.onCreateViewHolder(ViewGroup, int)
and BaseRecyclerAdapter.onBindViewHolder(RecyclerView.ViewHolder, int) methods are required to be implemented
to take a full advantage of this adapter class.
BaseRecyclerAdapter.SimpleViewHoldermContext, mLayoutInflater, mResourcesNO_ID, NO_POSITION| Constructor and Description |
|---|
SimpleRecyclerAdapter(Context context)
Creates a new instance of SimpleRecyclerAdapter without initial items data set.
|
SimpleRecyclerAdapter(Context context,
Item[] items)
Same as
SimpleRecyclerAdapter(Context, List) for array of initial items
data set. |
SimpleRecyclerAdapter(Context context,
List<Item> items)
Creates a new instance of SimpleRecyclerAdapter with the given initial items data
set.
|
| Modifier and Type | Method and Description |
|---|---|
void |
changeItems(List<Item> items)
Same as
ItemsAdapter.swapItems(List) without returning the old data set of items. |
Item |
getItem(int position)
Returns the item (model) containing data from this data set for the specified position.
|
int |
getItemCount()
Returns the total number of items in the data set held by the adapter.
|
List<Item> |
getItems()
Returns the current items data set of this adapter.
|
boolean |
hasItemAt(int position)
Returns a boolean flag indicating whether this data set has item that can provide data for the
specified position or not.
|
protected boolean |
onItemsChange(List<Item> newItems,
List<Item> oldItems)
Called from
swapItems(List) in order to handle change in items of this adapter. |
List<Item> |
swapItems(List<Item> items)
Changes items data set of this adapter and returns the old items data set.
|
getItemId, inflate, isEmpty, isEnabled, notifyDataSetActionSelected, onBindViewHolder, onCreateViewHolder, onDataSetActionSelected, registerOnDataChangeListener, registerOnDataSetActionListener, registerOnDataSetListener, restoreInstanceState, saveInstanceState, unregisterOnDataChangeListener, unregisterOnDataSetActionListener, unregisterOnDataSetListenerbindViewHolder, createViewHolder, getItemViewType, hasObservers, hasStableIds, notifyDataSetChanged, notifyItemChanged, notifyItemChanged, notifyItemInserted, notifyItemMoved, notifyItemRangeChanged, notifyItemRangeChanged, notifyItemRangeInserted, notifyItemRangeRemoved, notifyItemRemoved, onAttachedToRecyclerView, onBindViewHolder, onDetachedFromRecyclerView, onFailedToRecycleView, onViewAttachedToWindow, onViewDetachedFromWindow, onViewRecycled, registerAdapterDataObserver, setHasStableIds, unregisterAdapterDataObserverclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waithasStableIds, isEnabled, restoreInstanceState, saveInstanceStategetItemId, isEmpty, registerOnDataChangeListener, registerOnDataSetActionListener, registerOnDataSetListener, unregisterOnDataChangeListener, unregisterOnDataSetActionListener, unregisterOnDataSetListenerpublic SimpleRecyclerAdapter(@NonNull Context context)
context - Context in which will be this adapter used.SimpleRecyclerAdapter(Context, Object[]),
SimpleRecyclerAdapter(Context, List)public SimpleRecyclerAdapter(@NonNull Context context, @NonNull Item[] items)
SimpleRecyclerAdapter(Context, List) for array of initial items
data set.public SimpleRecyclerAdapter(@NonNull Context context, @NonNull List<Item> items)
context - Context in which will be this adapter used.items - List of items to be used as initial data set for this adapter.public void changeItems(@Nullable List<Item> items)
ItemsAdapterItemsAdapter.swapItems(List) without returning the old data set of items.changeItems in interface ItemsAdapter<Item>items - The desired items to be changed. May be null to clear the current ones.ItemsAdapter.getItems()@Nullable public List<Item> swapItems(@Nullable List<Item> items)
ItemsAdapterswapItems in interface ItemsAdapter<Item>items - The desired items to be changed. May be null to clear the current ones.null if this adapter does not have items data set
specified.ItemsAdapter.getItems()protected boolean onItemsChange(@Nullable List<Item> newItems, @Nullable List<Item> oldItems)
swapItems(List) in order to handle change in items of this adapter.
Note, that during this call this adapter has already the new items attached.
This implementation does nothing.
newItems - The new items data set for this adapter.oldItems - The old items data set of this adapter that has been replaced by the new one.True if change has been handled and appropriate callbacks has been fired to
registered observers, false if default RecyclerView.Adapter.notifyDataSetChanged() should be invoked.@Nullable public List<Item> getItems()
ItemsAdaptergetItems in interface ItemsAdapter<Item>null if there is no items data set provided
by this adapter.ItemsAdapter.changeItems(List),
ItemsAdapter.swapItems(List)public int getItemCount()
android.support.v7.widget.RecyclerView.AdaptergetItemCount in interface DataSet<Item>getItemCount in class RecyclerView.Adapter<VH extends RecyclerView.ViewHolder>DataSet.isEmpty(),
DataSet.hasItemAt(int),
DataSet.getItem(int)public boolean hasItemAt(int position)
DataSethasItemAt in interface DataSet<Item>position - The position of item to check.True if DataSet.getItem(int) can be called 'safely', false otherwise.@NonNull public Item getItem(int position)
DataSetgetItem in interface DataSet<Item>position - Position of the item to obtain.DataSet.hasItemAt(int),
DataSet.getItemId(int)