Skip to content

Most visited

Recently visited

navigation

DiffUtil.DiffResult

public static class DiffUtil.DiffResult
extends Object

java.lang.Object
   ↳ android.support.v7.util.DiffUtil.DiffResult


This class holds the information about the result of a calculateDiff(Callback, boolean) call.

You can consume the updates in a DiffResult via dispatchUpdatesTo(ListUpdateCallback) or directly stream the results into a RecyclerView.Adapter via dispatchUpdatesTo(RecyclerView.Adapter).

Summary

Public methods

void dispatchUpdatesTo(ListUpdateCallback updateCallback)

Dispatches update operations to the given Callback.

void dispatchUpdatesTo(Adapter adapter)

Dispatches the update events to the given adapter.

Inherited methods

From class java.lang.Object

Public methods

dispatchUpdatesTo

added in version 24.2.0
void dispatchUpdatesTo (ListUpdateCallback updateCallback)

Dispatches update operations to the given Callback.

These updates are atomic such that the first update call effects every update call that comes after it (the same as RecyclerView).

Parameters
updateCallback ListUpdateCallback: The callback to receive the update operations.

See also:

dispatchUpdatesTo

added in version 24.2.0
void dispatchUpdatesTo (Adapter adapter)

Dispatches the update events to the given adapter.

For example, if you have an Adapter that is backed by a List, you can swap the list with the new one then call this method to dispatch all updates to the RecyclerView.

     List oldList = mAdapter.getData();
     DiffResult result = DiffUtil.calculateDiff(new MyCallback(oldList, newList));
     mAdapter.setData(newList);
     result.dispatchUpdatesTo(mAdapter);
 

Note that the RecyclerView requires you to dispatch adapter updates immediately when you change the data (you cannot defer notify* calls). The usage above adheres to this rule because updates are sent to the adapter right after the backing data is changed, before RecyclerView tries to read it.

On the other hand, if you have another AdapterDataObserver that tries to process events synchronously, this may confuse that observer because the list is instantly moved to its final state while the adapter updates are dispatched later on, one by one. If you have such an AdapterDataObserver, you can use dispatchUpdatesTo(ListUpdateCallback) to handle each modification manually.

Parameters
adapter Adapter: A RecyclerView adapter which was displaying the old list and will start displaying the new list.

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a one-minute survey?
Help us improve Android tools and documentation.