public class ListViewDataSourceAdapter extends ListViewAdapter implements DataChangedListener
RadListView
that supports
data operations like grouping, filtering and sorting.
Adapters provide a binding from an app-specific data set to views that are displayed
within a RadListView
.
Constructor and Description |
---|
ListViewDataSourceAdapter(List items)
Creates an instance of the
ListViewDataSourceAdapter class. |
Modifier and Type | Method and Description |
---|---|
void |
add(int index,
Object item)
Inserts the specified object into this
ListViewAdapter
at the specified index. |
void |
add(int index,
Object item,
boolean invalidateDescriptors)
Inserts the specified object into this
ListViewAdapter
at the specified index. |
void |
add(Object item)
Adds the specified item at the end of the items in
this
ListViewAdapter . |
void |
add(Object item,
boolean invalidateDescriptors)
Adds the specified item at the end of the items in
this
ListViewAdapter . |
void |
addFilterDescriptor(Function<Object,Boolean> filterDescriptor)
Adds a filter descriptor that specifies how the items on this list can be filtered.
|
void |
addGroupDescriptor(Function<Object,Object> groupDescriptor)
Adds a group descriptor that specifies how the items on this list can be grouped.
|
void |
addSortDescriptor(Function2<Object,Object,Integer> sortDescriptor)
Adds a sort descriptor that specifies how the items on this list can be sorted.
|
boolean |
canReorder(int position)
Determines if the item at the provided position can be reordered.
|
boolean |
canSelect(int position)
Determines if the item at the provided position is selectable.
|
boolean |
canSwipe(int position)
Determines if the item at the provided position can be swiped.
|
void |
clearFilterDescriptors()
Clears the list of filter descriptors used by this instance.
|
void |
clearGroupDescriptors()
Clears the list of group descriptors used by this instance.
|
void |
clearSortDescriptors()
Clears the list of sort descriptors used by this instance.
|
void |
dataChanged(DataChangeInfo info) |
int |
getBaseItemCount()
Returns the total number of items handled by the adapter after the data operation are performed.
|
DataItem |
getDataItem(int position)
Return the
DataItem on the provided position. |
int |
getGroupViewType(Object group)
Return the view type of provided group header item for the purposes
of view recycling.
|
int |
getHeaderPosition(int position) |
Object |
getItem(int position)
Return the item on the provided position.
|
int |
getItemCount() |
long |
getItemId(int position) |
int |
getItemViewType(int position) |
int |
getItemViewType(Object item)
Return the view type of provided item for the purposes
of view recycling.
|
int |
getPosition(long id)
Return the position of the item with the provided id.
|
int |
getPosition(Object searchItem)
Return the position of the item that is provided.
|
void |
invalidateDescriptors()
Invalidates the descriptors and updates the list with any updates on the list.
|
boolean |
isGroupHeader(int position)
Return
true if the item at the specified position is a group header
and false otherwise. |
void |
onBindGroupViewHolder(ListViewHolder holder,
Object groupKey)
Called by
RadListView to display the specified group header. |
void |
onBindItemViewHolder(ListViewHolder holder,
Object entity)
Called by
RadListView to display the specified item. |
void |
onBindViewHolder(ListViewHolder holder,
int position) |
ListViewHolder |
onCreateGroupViewHolder(ViewGroup parent,
int viewType)
Called when
RadListView needs a new ListViewHolder
of the given type to represent a group header item. |
ListViewHolder |
onCreateItemViewHolder(ViewGroup parent,
int viewType)
Called when
RadListView needs a new ListViewHolder
of the given type to represent an item from the list. |
ListViewHolder |
onCreateViewHolder(ViewGroup parent,
int viewType) |
Object |
remove(int index)
Removes the object at the specified index from the list
of items in this
ListViewAdapter . |
Object |
remove(int index,
boolean invalidateDescriptors)
Removes the object at the specified index from the list
of items in this
ListViewAdapter . |
boolean |
remove(Object item)
Removes the first occurrence of the specified object from the list
of items in this
ListViewAdapter . |
boolean |
remove(Object item,
boolean invalidateDescriptors)
Removes the first occurrence of the specified object from the list
of items in this
ListViewAdapter . |
void |
removeFilterDescriptor(Function<Object,Boolean> filterDescriptor)
Removes the specified filter descriptor from the descriptors used by this instance.
|
void |
removeGroupDescriptor(Function<Object,Object> groupDescriptor)
Removes the specified group descriptor from the descriptors used by this instance.
|
void |
removeSortDescriptor(Function2<Object,Object,Integer> sortDescriptor)
Removes the specified sort descriptor from the descriptors used by this instance.
|
boolean |
reorderItem(int oldPosition,
int newPosition)
Provides the reorder operation as requested by an
ItemReorderBehavior instance. |
void |
setItems(List items)
Sets a new list of items to be handled by this adapter instance.
|
canDeselect, getItem, getItemId, getItems, notifyLoadingFinished, notifyRefreshFinished, notifySwipeExecuteFinished, onBindSwipeContentHolder, onCreateSwipeContentHolder
bindViewHolder, createViewHolder, hasObservers, hasStableIds, notifyDataSetChanged, notifyItemChanged, notifyItemChanged, notifyItemInserted, notifyItemMoved, notifyItemRangeChanged, notifyItemRangeChanged, notifyItemRangeInserted, notifyItemRangeRemoved, notifyItemRemoved, onAttachedToRecyclerView, onBindViewHolder, onDetachedFromRecyclerView, onFailedToRecycleView, onViewAttachedToWindow, onViewDetachedFromWindow, onViewRecycled, registerAdapterDataObserver, setHasStableIds, unregisterAdapterDataObserver
public ListViewDataSourceAdapter(List items)
ListViewDataSourceAdapter
class.items
- a list of items that will be handled by this adapterpublic void addGroupDescriptor(Function<Object,Object> groupDescriptor)
myAdapter.addGroupDescriptor(new Function <String, Character >() {
@Override
public Character apply(String argument) {
return argument.charAt(0);
}
});
groupDescriptor
- the group descriptor to use.public void removeGroupDescriptor(Function<Object,Object> groupDescriptor)
groupDescriptor
- the group descriptor to remove.public void clearGroupDescriptors()
public void addSortDescriptor(Function2<Object,Object,Integer> sortDescriptor)
myAdapter.addGroupDescriptor(new Function2 <MyItem, MyItem, Integer >() {
@Override
public Integer apply(MyItem argument1, MyItem argument2) {
return argument1.getName().compareTo(argument2.getName);
}
});
sortDescriptor
- the sort descriptor to use.public void removeSortDescriptor(Function2<Object,Object,Integer> sortDescriptor)
sortDescriptor
- the sort descriptor to remove.public void clearSortDescriptors()
public void addFilterDescriptor(Function<Object,Boolean> filterDescriptor)
myAdapter.addFilterDescriptor(new Function <String, Boolean >() {
@Override
public Boolean apply(String argument) {
return argument.startsWith("s");
}
});
filterDescriptor
- the filter descriptor to use.public void removeFilterDescriptor(Function<Object,Boolean> filterDescriptor)
filterDescriptor
- the filter descriptor to remove.public void clearFilterDescriptors()
public void invalidateDescriptors()
public void add(Object item)
ListViewAdapter
ListViewAdapter
.add
in class ListViewAdapter
item
- the object to add.public void add(Object item, boolean invalidateDescriptors)
ListViewAdapter
.item
- the object to add.invalidateDescriptors
- specifies whether the descriptors will be
invalidated after this change.public void add(int index, Object item)
ListViewAdapter
ListViewAdapter
at the specified index. The object is inserted before the current element at the
specified index.add
in class ListViewAdapter
index
- the index at which to insert.item
- the object to add.public void add(int index, Object item, boolean invalidateDescriptors)
ListViewAdapter
at the specified index. The object is inserted before the current element at the
specified index.index
- the index at which to insert.item
- the object to add.invalidateDescriptors
- specifies whether the descriptors will be
invalidated after this change.public boolean remove(Object item)
ListViewAdapter
ListViewAdapter
.remove
in class ListViewAdapter
item
- the object to remove.public boolean remove(Object item, boolean invalidateDescriptors)
ListViewAdapter
.item
- the object to remove.invalidateDescriptors
- specifies whether the descriptors will be
invalidated after this change.public Object remove(int index)
ListViewAdapter
ListViewAdapter
.remove
in class ListViewAdapter
index
- the index of the object to remove.public Object remove(int index, boolean invalidateDescriptors)
ListViewAdapter
.index
- the index of the object to remove.invalidateDescriptors
- specifies whether the descriptors will be
invalidated after this change.public DataItem getDataItem(int position)
DataItem
on the provided position.
Returns null if the position exceeds the bounds of the list of items.position
- the position of the data itempublic boolean isGroupHeader(int position)
true
if the item at the specified position is a group header
and false
otherwise.position
- the position of the itempublic void setItems(List items)
ListViewAdapter
setItems
in class ListViewAdapter
ListViewAdapter.getItems()
public void dataChanged(DataChangeInfo info)
dataChanged
in interface DataChangedListener
public Object getItem(int position)
ListViewAdapter
getItem
in class ListViewAdapter
position
- the position of the itempublic boolean canSwipe(int position)
ListViewAdapter
canSwipe
in class ListViewAdapter
SwipeRefreshBehavior
public boolean canSelect(int position)
ListViewAdapter
canSelect
in class ListViewAdapter
SelectionBehavior
public int getPosition(long id)
ListViewAdapter
INVALID_ID
if an item with that id is not found.getPosition
in class ListViewAdapter
id
- the item id to querypublic int getPosition(Object searchItem)
ListViewAdapter
-1
if the item is not found.getPosition
in class ListViewAdapter
searchItem
- the item to querypublic boolean canReorder(int position)
ListViewAdapter
canReorder
in class ListViewAdapter
ItemReorderBehavior
public boolean reorderItem(int oldPosition, int newPosition)
ListViewAdapter
ItemReorderBehavior
instance.reorderItem
in class ListViewAdapter
ItemReorderBehavior
public long getItemId(int position)
getItemId
in class ListViewAdapter
public final ListViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
onCreateViewHolder
in class ListViewAdapter
public final void onBindViewHolder(ListViewHolder holder, int position)
onBindViewHolder
in class ListViewAdapter
public final int getItemViewType(int position)
getItemViewType
in class RecyclerView.Adapter<ListViewHolder>
public int getItemViewType(Object item)
item
- item to querygetGroupViewType(Object)
public int getGroupViewType(Object group)
ITEM_VIEW_TYPE_GROUP
,
making the assumption of a single view type for the headers in this adapter.
Consider using id resources to uniquely identify group header item view types.group
- group header to querygetItemViewType(Object)
public final int getItemCount()
getItemCount
in class ListViewAdapter
public int getBaseItemCount()
getItemCount()
.getBaseItemCount()
public ListViewHolder onCreateGroupViewHolder(ViewGroup parent, int viewType)
RadListView
needs a new ListViewHolder
of the given type to represent a group header item.
The method will be called for negative values of viewType.
Note that if the itemView type is negative, the view will be treated like a group header.
The new ViewHolder will be used to display items of the adapter using
onBindGroupViewHolder(ListViewHolder, Object)
. Since it will be re-used to display different
items in the data set, it is a good idea to cache references to sub views of the View to
avoid unnecessary View.findViewById(int)
calls.parent
- The ViewGroup into which the new View will be added after it is bound to
an adapter position.viewType
- The view type of the new View.onBindGroupViewHolder(ListViewHolder, Object)
,
onCreateItemViewHolder(android.view.ViewGroup, int)
public void onBindGroupViewHolder(ListViewHolder holder, Object groupKey)
RadListView
to display the specified group header.
This method should update the contents of the RecyclerView.ViewHolder.itemView
to
reflect the given group header item.holder
- The ViewHolder which should be updated to represent the contents of the
group key that is provided.groupKey
- The group key that should be bound.onBindItemViewHolder(ListViewHolder, Object)
,
onCreateGroupViewHolder(android.view.ViewGroup, int)
public ListViewHolder onCreateItemViewHolder(ViewGroup parent, int viewType)
RadListView
needs a new ListViewHolder
of the given type to represent an item from the list.
The method will be called for non-negative values of viewType.
Note that if the itemView type is negative, the view will be treated like a group header.
The new ViewHolder will be used to display items of the adapter using
onBindItemViewHolder(ListViewHolder, Object)
. Since it will be re-used to display different
items in the data set, it is a good idea to cache references to sub views of the View to
avoid unnecessary View.findViewById(int)
calls.parent
- The ViewGroup into which the new View will be added after it is bound to
an adapter position.viewType
- The view type of the new View.onBindItemViewHolder(ListViewHolder, Object)
,
onCreateGroupViewHolder(android.view.ViewGroup, int)
public void onBindItemViewHolder(ListViewHolder holder, Object entity)
RadListView
to display the specified item.
This method should update the contents of the RecyclerView.ViewHolder.itemView
to
reflect the given item.holder
- The ViewHolder which should be updated to represent the contents of the
group key that is provided.entity
- The entity that should be bound.onBindGroupViewHolder(ListViewHolder, Object)
,
onCreateItemViewHolder(android.view.ViewGroup, int)
public int getHeaderPosition(int position)