java.lang.Object | ||
↳ | android.support.v7.util.SortedList.Callback<T2> | |
↳ | android.support.v7.util.SortedList.BatchedCallback<T2> |
A callback implementation that can batch notify events dispatched by the SortedList.
This class can be useful if you want to do multiple operations on a SortedList but don't want to dispatch each event one by one, which may result in a performance issue.
For example, if you are going to add multiple items to a SortedList, BatchedCallback call
convert individual onInserted(index, 1)
calls into one
onInserted(index, N)
if items are added into consecutive indices. This change
can help RecyclerView resolve changes much more easily.
If consecutive changes in the SortedList are not suitable for batching, BatchingCallback
dispatches them as soon as such case is detected. After your edits on the SortedList is
complete, you must always call dispatchLastEvent()
to flush
all changes to the Callback.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Creates a new BatchedCallback that wraps the provided Callback.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Called by the SortedList when it wants to check whether two items have the same data
or not.
| |||||||||||
Called by the SortedList to decide whether two object represent the same Item or not.
| |||||||||||
Similar to
compare(Object, Object) , should compare two and
return how they should be ordered.
| |||||||||||
This method dispatches any pending event notifications to the wrapped Callback.
| |||||||||||
Called by the SortedList when the item at the given position is updated.
| |||||||||||
Called by the SortedList when an item is inserted at the given position.
| |||||||||||
Called by the SortedList when an item changes its position in the list.
| |||||||||||
Called by the SortedList when an item is removed from the given position.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.support.v7.util.SortedList.Callback
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
java.util.Comparator
|
Creates a new BatchedCallback that wraps the provided Callback.
wrappedCallback | The Callback which should received the data change callbacks.
Other method calls (e.g. compare(Object, Object) from
the SortedList are directly forwarded to this Callback.
|
---|
Called by the SortedList when it wants to check whether two items have the same data
or not. SortedList uses this information to decide whether it should call
onChanged(int, int)
or not.
SortedList uses this method to check equality instead of equals(Object)
so
that you can change its behavior depending on your UI.
For example, if you are using SortedList with a RecyclerView.Adapter
, you should
return whether the items' visual representations are the same or not.
oldItem | The previous representation of the object. |
---|---|
newItem | The new object that replaces the previous one. |
Called by the SortedList to decide whether two object represent the same Item or not.
For example, if your items have unique ids, this method should check their equality.
item1 | The first item to check. |
---|---|
item2 | The second item to check. |
Similar to compare(Object, Object)
, should compare two and
return how they should be ordered.
o1 | The first object to compare. |
---|---|
o2 | The second object to compare. |
This method dispatches any pending event notifications to the wrapped Callback. You must always call this method after you are done with editing the SortedList.
Called by the SortedList when the item at the given position is updated.
position | The position of the item which has been updated. |
---|---|
count | The number of items which has changed. |
Called by the SortedList when an item is inserted at the given position.
position | The position of the new item. |
---|---|
count | The number of items that have been added. |
Called by the SortedList when an item changes its position in the list.
fromPosition | The previous position of the item before the move. |
---|---|
toPosition | The new position of the item. |
Called by the SortedList when an item is removed from the given position.
position | The position of the item which has been removed. |
---|---|
count | The number of items which have been removed. |