public abstract class BetterRecyclerAdapter<M,VH extends RecyclerView.ViewHolder>
extends <any>
| Modifier and Type | Class and Description |
|---|---|
static interface |
BetterRecyclerAdapter.Filter<T>
Inner Classes & Interfaces
|
static interface |
BetterRecyclerAdapter.OnItemClickListener<T>
The interface for detecting item click events from within the adapter, this listener
is triggered by
onItemClick(android.view.View, int) |
static interface |
BetterRecyclerAdapter.OnItemLongClickListener<T>
The interface for detecting item long click events from within the adapter
|
| Modifier and Type | Field and Description |
|---|---|
protected java.util.ArrayList<M> |
filteredItems |
protected java.util.ArrayList<M> |
items
Variables
|
| Constructor and Description |
|---|
BetterRecyclerAdapter()
Default Constructor
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(int index,
M object)
Add a single object at the given index
|
void |
add(M object)
Add a single object to this adapter
|
void |
addAll(java.util.Collection<? extends M> collection)
Add a collection of objects to this adapter
|
void |
clear()
Clear this adapter of all items
|
void |
clearFilter()
Clear this adapter's filter and re-apply
This endpoints with notify the adapter of content change
|
void |
filter(java.lang.CharSequence constraints)
Filter this adapter with the specified constraints
This endpoints with notify the adapter of content change
|
protected BetterRecyclerAdapter.Filter<M> |
getFilter()
Override to return the applicable filter for this adapter to
filter with given specified constraint
|
M |
getItem(int position)
Get an item from this adapter at a specific index
|
int |
getItemCount()
Get the active number of items in this adapter, i.e.
|
long |
getItemId(int position)
Get the item Id for a given position
|
java.util.List<M> |
getItems()
Get all the items in this adapter
|
java.util.List<M> |
getUnfilteredItems()
Get a list of the raw underlying dataset of items
|
protected boolean |
isFiltered()
Return whether or not this adapter is filtered
|
void |
moveItem(int start,
int end)
Move an item around in the underlying array
|
void |
onBindViewHolder(VH vh,
int i)
Intercept the bind View holder method to wire up the item click listener only if
the listener is set by the user
CAVEAT: Be sure that you still override this method and call it's super (or don't if you want
to override this functionality and use the
onItemClick(android.view.View, int) method) |
protected void |
onFiltered()
Override to listen to when the adapter finishes filtering the dataset
|
protected void |
onItemClick(android.view.View view,
int position)
Call this to trigger the user set item click listener
|
protected void |
onItemLongClick(android.view.View view,
int position)
Call this to trigger the user set item long click lisetner
|
protected void |
onItemMoved(M item,
int start,
int end)
Override to observe reorder changes in the underlying true data set
|
protected void |
onSort(java.util.List<M> items)
Override so you can sort the items in the array according
to your specification.
|
M |
remove(int index)
Remove an item at the given index
|
void |
remove(M object)
Remove a specific object from this adapter
|
void |
set(int index,
M object)
Update an item in the collection of objects with a new object
|
void |
setEmptyView(android.view.View emptyView)
Set the empty view to be used so that
|
void |
setOnItemClickListener(BetterRecyclerAdapter.OnItemClickListener<M> itemClickListener)
Set the item click listener for this adapter
|
void |
setOnItemLongClickListener(BetterRecyclerAdapter.OnItemLongClickListener<M> itemLongClickListener)
Set the item long click listener for this adapter
|
void |
sort(java.util.Comparator<M> comparator)
Sort the items in this adapter by a given
Comparator |
protected java.util.ArrayList<M> items
protected java.util.ArrayList<M> filteredItems
protected void onItemClick(android.view.View view,
int position)
view - the view that was clickedposition - the position that was clickedprotected void onItemLongClick(android.view.View view,
int position)
view - the view that was clickedposition - the position that was clickedprotected void onSort(java.util.List<M> items)
items - the list of items needing sortingprotected void onFiltered()
protected void onItemMoved(M item, int start, int end)
start - the real start index, non-filteredend - the real end index, non-filteredprotected BetterRecyclerAdapter.Filter<M> getFilter()
public void setEmptyView(android.view.View emptyView)
emptyView - public void setOnItemClickListener(BetterRecyclerAdapter.OnItemClickListener<M> itemClickListener)
public void setOnItemLongClickListener(BetterRecyclerAdapter.OnItemLongClickListener<M> itemLongClickListener)
public void add(M object)
object - the object to addpublic void add(int index,
M object)
index - the position to add the object atobject - the object to addpublic void addAll(java.util.Collection<? extends M> collection)
collection - the collection of objects to addpublic void set(int index,
M object)
index - the index of the object to updateobject - the new object to replace at index positionpublic void clear()
public void remove(M object)
object - the object to removepublic M remove(int index)
index - the index of the item to removepublic void moveItem(int start,
int end)
start - the item to moveend - the position to move topublic void sort(java.util.Comparator<M> comparator)
Comparatorcomparator - the comparator to sort withpublic M getItem(int position)
position - the position of the item to retrievepublic java.util.List<M> getItems()
public java.util.List<M> getUnfilteredItems()
protected boolean isFiltered()
public void filter(java.lang.CharSequence constraints)
constraints - the constraints to filter withpublic void clearFilter()
public int getItemCount()
public void onBindViewHolder(VH vh, int i)
onItemClick(android.view.View, int) method)vh - the view holderi - the position being boundpublic long getItemId(int position)
position -