public abstract class BetterRecyclerAdapter<M,VH extends RecyclerView.ViewHolder>
extends <any>
| Modifier and Type | Class and Description |
|---|---|
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) |
| Modifier and Type | Field and Description |
|---|---|
protected java.lang.String |
filter |
protected java.util.ArrayList<M> |
filteredItems |
protected java.util.ArrayList<M> |
items |
| 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 |
clearQuery()
Clear out the current query
|
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) |
java.util.List<M> |
getItems()
Get all the items in this adapter
|
int |
getItemViewType(int position)
Called to get the view type of an item at a given position
|
java.util.List<M> |
getUnfilteredItems()
Get all the unfiltered items in this adapter
|
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 this method to be notified when the adapter is filtered
|
protected void |
onItemClick(android.view.View view,
int position)
Call this to trigger the user set item click listener
|
protected boolean |
onQuery(M item,
java.lang.String query)
Override this method to apply filtering to your content
so you can supply queries to the adapter to filter your content out
for search
|
protected void |
onSort(java.util.List<M> items)
Override so you can sort the items in the array according
to your specification.
|
void |
query(java.lang.String query)
Apply a query to this adapter
|
M |
remove(int index)
Remove an item at the given index
|
void |
remove(M object)
Remove a specific object from this adapter
|
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 |
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 java.lang.String filter
protected void onItemClick(android.view.View view,
int position)
view - the view that was clickedposition - the position that was clickedprotected boolean onQuery(M item, java.lang.String query)
item - the item to filter checkquery - the query to check withprotected void onSort(java.util.List<M> items)
items - the list of items needing sortingprotected void onFiltered()
public void setEmptyView(android.view.View emptyView)
emptyView - public void setOnItemClickListener(BetterRecyclerAdapter.OnItemClickListener<M> itemClickListener)
public void query(java.lang.String query)
query - querypublic void clearQuery()
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 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()
public int getItemCount()
public void onBindViewHolder(VH vh, int i)
onItemClick(android.view.View, int) method)vh - the view holderi - the position being boundpublic int getItemViewType(int position)
position - the position of the item to get the view type ofpublic long getItemId(int position)