VH
- The ViewHolder to useT
- The object type for the listpublic abstract class RecyclerListAdapter<VH extends android.support.v7.widget.RecyclerView.ViewHolder,T>
extends android.support.v7.widget.RecyclerView.Adapter<VH>
Modifier and Type | Field and Description |
---|---|
protected java.util.List<T> |
items |
protected java.lang.Object |
lock |
protected boolean |
notifyOnChange |
Constructor and Description |
---|
RecyclerListAdapter()
Creates an adapter with no initial items
|
RecyclerListAdapter(java.util.List<T> itemList)
Creates an adapter with the specified items
|
Modifier and Type | Method and Description |
---|---|
void |
add(int position,
T item)
Adds the specified item to the list with the specified position
|
void |
add(T item)
Adds the specified item to the end of the list
|
void |
addAll(java.util.List<T> itemList)
Adds all the specified items to the list
|
void |
clear()
Clears all the items from the list
|
T |
getItem(int position)
Retrieves the item with the specified position in the adapter.
|
int |
getItemCount()
Retrieves the number of items for the adapter.
|
int |
getPosition(T item)
Searches the items for the specified object and returns the index of the
first occurrence.
|
void |
move(int originalPosition,
int endPosition)
Moves the item at the
originalPosition to the endPosition . |
void |
notifyItemsSwapped(int positionOne,
int positionTwo)
Notify any registered observers that the item reflected at
positionOne
has been moved to positionTwo and vice-versa. |
void |
remove(int position)
Removes the item with the specified position from the list
|
void |
remove(T item)
Removes the specified item from the list
|
void |
set(java.util.List<T> itemList)
Clears all the current items in the list and
adds all the specified items to the list
|
void |
setNotifyOnChange(boolean notifyOnChange)
Control whether methods that change the list automatically call notifyDataSetChanged().
|
void |
sort(java.util.Comparator<? super T> comparator)
Sorts the items in the adapter using the specified comparator
|
void |
swap(int positionOne,
int positionTwo)
Swaps the items with the specified positions in the list.
|
bindViewHolder, createViewHolder, getItemId, getItemViewType, hasObservers, hasStableIds, notifyDataSetChanged, notifyItemChanged, notifyItemChanged, notifyItemInserted, notifyItemMoved, notifyItemRangeChanged, notifyItemRangeChanged, notifyItemRangeInserted, notifyItemRangeRemoved, notifyItemRemoved, onAttachedToRecyclerView, onBindViewHolder, onBindViewHolder, onCreateViewHolder, onDetachedFromRecyclerView, onFailedToRecycleView, onViewAttachedToWindow, onViewDetachedFromWindow, onViewRecycled, registerAdapterDataObserver, setHasStableIds, unregisterAdapterDataObserver
@Nullable protected java.util.List<T> items
protected boolean notifyOnChange
protected final java.lang.Object lock
public RecyclerListAdapter()
public RecyclerListAdapter(@Nullable java.util.List<T> itemList)
itemList
- The list of initial items for the adapterpublic int getItemCount()
getItemCount
in class android.support.v7.widget.RecyclerView.Adapter<VH extends android.support.v7.widget.RecyclerView.ViewHolder>
@Nullable public T getItem(int position)
position
- The items position in the listpublic int getPosition(T item)
item
- The object to search forpublic void clear()
public void set(@NonNull java.util.List<T> itemList)
itemList
- the list of items to addpublic void add(T item)
item
- The item to add to the listpublic void add(int position, T item)
position
- The position to insert the item atitem
- The item to add to the listpublic void addAll(@NonNull java.util.List<T> itemList)
itemList
- The list of items to addpublic void remove(T item)
item
- The item to remove from the listpublic void remove(int position)
position
- The position for the item to removepublic void swap(int positionOne, int positionTwo)
positionOne
- The position of the first item to swappositionTwo
- The position of the second item to swappublic void move(int originalPosition, int endPosition)
originalPosition
to the endPosition
.
If the endPosition
is greater than the number of items, it will be added to the
end of the list instead.originalPosition
- The position the object is in that needs to be movedendPosition
- The end position for the item being movedpublic void notifyItemsSwapped(int positionOne, int positionTwo)
positionOne
has been moved to positionTwo
and vice-versa.
This is a structural change event. Representations of other existing items in the data set are still considered up to date and will not be rebound, though their positions may be altered.
positionOne
- The position of the first item movedpositionTwo
- The position of the second item movedpublic void setNotifyOnChange(boolean notifyOnChange)
notifyOnChange
- if true, modifications to the list will automatically call notifyDataSetChanged()public void sort(java.util.Comparator<? super T> comparator)
comparator
- The comparator to sort the list with