blob: 6085e0c2b33f40d3f75fb166fe5fa4d86ba25840 [file] [log] [blame]
<html devsite="true">
<head>
<title>AsyncPagedListDiffer</title>
{% setvar book_path %}/reference/kotlin/androidx/_book.yaml{% endsetvar %}
{% include "_shared/_reference-head-tags.html" %}
</head>
<body>
<h1>AsyncPagedListDiffer</h1>
{% setvar page_path %}androidx/paging/AsyncPagedListDiffer.html{% endsetvar %}
{% setvar can_switch %}1{% endsetvar %}
{% include "reference/_kotlin_switcher2.md" %}
<p>
<pre>open class AsyncPagedListDiffer&lt;T&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>&gt;</pre>
</p>
<hr>
<aside class="caution"><strong>This class is deprecated.</strong><br>AsyncPagedListDiffer is deprecated and has been replaced by AsyncPagingDataDiffer</aside>
<p>Helper object for mapping a <code><a href="/reference/kotlin/androidx/paging/PagedList.html">androidx.paging.PagedList</a></code> into a <a href="[androidx.recyclerview.widget.RecyclerView.Adapter]">androidx.recyclerview.widget.RecyclerView.Adapter</a>.</p>
<p>For simplicity, the <code><a href="/reference/kotlin/androidx/paging/PagedListAdapter.html">PagedListAdapter</a></code> wrapper class can often be used instead of the differ directly. This diff class is exposed for complex cases, and where overriding an adapter base class to support paging isn't convenient.</p>
<p>When consuming a <a href="[LiveData]">LiveData</a> of PagedList, you can observe updates and dispatch them directly to <code><a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.html#submitList(androidx.paging.PagedList)">submitList</a></code>. The AsyncPagedListDiffer then can present this updating data set simply for an adapter. It listens to PagedList loading callbacks, and uses DiffUtil on a background thread to compute updates as new PagedLists are received.</p>
<p>It provides a simple list-like API with <code><a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.html#getItem(kotlin.Int)">getItem</a></code> and <code><a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.html#itemCount()">itemCount</a></code> for an adapter to acquire and present data objects.</p>
<p>A complete usage pattern with Room would look like this:</p>
<pre class="prettyprint">@Dao<br>interface UserDao {<br> @Query(&quot;SELECT * FROM user ORDER BY lastName ASC&quot;)<br> public abstract DataSource.Factory&lt;Integer, User&gt; usersByLastName();<br>}<br><br>class MyViewModel extends ViewModel {<br> public final LiveData&lt;PagedList&lt;User&gt;&gt; usersList;<br> public MyViewModel(UserDao userDao) {<br> usersList = new LivePagedListBuilder&lt;&gt;(<br> userDao.usersByLastName(), /* page size */20).build();<br> }<br>}<br><br>class MyActivity extends AppCompatActivity {<br> @Override<br> public void onCreate(Bundle savedState) {<br> super.onCreate(savedState);<br> MyViewModel viewModel = new ViewModelProvider(this).get(MyViewModel.class);<br> RecyclerView recyclerView = findViewById(R.id.user_list);<br> final UserAdapter adapter = new UserAdapter();<br> viewModel.usersList.observe(this, pagedList -&gt; adapter.submitList(pagedList));<br> recyclerView.setAdapter(adapter);<br> }<br>}<br><br>class UserAdapter extends RecyclerView.Adapter&amp;lt;UserViewHolder&gt; {<br> private final AsyncPagedListDiffer&amp;lt;User&gt; differ =<br> new AsyncPagedListDiffer(this, DIFF_CALLBACK);<br> @Override<br> public int getItemCount() {<br> return differ.getItemCount();<br> }<br> public void submitList(PagedList&amp;lt;User&gt; pagedList) {<br> differ.submitList(pagedList);<br> }<br> @Override<br> public void onBindViewHolder(UserViewHolder holder, int position) {<br> User user = differ.getItem(position);<br> if (user != null) {<br> holder.bindTo(user);<br> } else {<br> // Null defines a placeholder item - AsyncPagedListDiffer will automatically<br> // invalidate this row when the actual object is loaded from the database<br> holder.clear();<br> }<br> }<br> public static final DiffUtil.ItemCallback&amp;lt;User&gt; DIFF_CALLBACK =<br> new DiffUtil.ItemCallback&amp;lt;User&gt;() {<br> @Override<br> public boolean areItemsTheSame(<br> @NonNull User oldUser, @NonNull User newUser) {<br> // User properties may have changed if reloaded from the DB, but ID is fixed<br> return oldUser.getId() == newUser.getId();<br> }<br> @Override<br> public boolean areContentsTheSame(@NonNull User oldUser, @NonNull User newUser) {<br> // NOTE: if you use equals, your object must properly override Object#equals()<br> // Incorrectly returning false here will result in too many animations.<br> return oldUser.equals(newUser);<br> }<br> }<br>}</pre>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2">Parameters</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>&lt;T&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>&gt;</code></td>
<td width="100%">
<p>Type of the PagedLists this differ will receive.</p>
</td>
</tr>
</tbody>
</table>
</div>
<h2>Summary</h2>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2"><h3>Nested types</h3></th>
</tr>
</thead>
<tbody>
<tr>
<td><code><a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.PagedListListener.html">AsyncPagedListDiffer.PagedListListener</a></code></td>
<td width="100%">
<p>Listener for when the current <code><a href="/reference/kotlin/androidx/paging/PagedList.html">PagedList</a></code> is updated.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2"><h3>Public properties</h3></th>
</tr>
</thead>
<tbody>
<tr>
<td><code>open <a href="/reference/kotlin/androidx/paging/PagedList.html">PagedList</a>&lt;T&gt;?</code></td>
<td width="100%">
<div><code><a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.html#currentList()">currentList</a></code></div>
<p>Returns the PagedList currently being displayed by the differ.</p>
</td>
</tr>
<tr>
<td><code>open <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html">Int</a></code></td>
<td width="100%">
<div><code><a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.html#itemCount()">itemCount</a></code></div>
<p>Get the number of items currently presented by this Differ.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2"><h3>Public constructors</h3></th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div><code>&lt;T&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>&gt; <span><del><a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.html#AsyncPagedListDiffer(RecyclerView.Adapter&lt;*&gt;,DiffUtil.ItemCallback&lt;T&gt;)">AsyncPagedListDiffer</a></del></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;adapter:&nbsp;<a href="/reference/kotlin/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>&lt;<a href="/reference/kotlin/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;diffCallback:&nbsp;<a href="/reference/kotlin/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>&lt;T&gt;<br>)</code></div>
<p>Convenience for</p>
<pre class="prettyprint">AsyncPagedListDiffer(<br> AdapterListUpdateCallback(adapter),<br> AsyncDifferConfig.Builder&lt;T&gt;(diffCallback).build()<br>)</pre>
</td>
</tr>
<tr>
<td>
<div><code>&lt;T&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>&gt; <span><del><a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.html#AsyncPagedListDiffer(ListUpdateCallback,AsyncDifferConfig&lt;T&gt;)">AsyncPagedListDiffer</a></del></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;listUpdateCallback:&nbsp;<a href="/reference/kotlin/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;config:&nbsp;<a href="/reference/kotlin/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>&lt;T&gt;<br>)</code></div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2"><h3>Public functions</h3></th>
</tr>
</thead>
<tbody>
<tr>
<td><code>open <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a></code></td>
<td width="100%">
<div><code><a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.html#addLoadStateListener(kotlin.Function2)">addLoadStateListener</a>(listener:&nbsp;(<a href="/reference/kotlin/androidx/paging/LoadType.html">LoadType</a>,&nbsp;<a href="/reference/kotlin/androidx/paging/LoadState.html">LoadState</a>)&nbsp;-&gt;&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a>)</code></div>
<p>Add a <code><a href="/reference/kotlin/androidx/paging/LoadState.html">LoadState</a></code> listener to observe the loading state of the current <code><a href="/reference/kotlin/androidx/paging/PagedList.html">PagedList</a></code>.</p>
</td>
</tr>
<tr>
<td><code>open <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a></code></td>
<td width="100%">
<div><code><a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.html#addPagedListListener(androidx.paging.AsyncPagedListDiffer.PagedListListener)">addPagedListListener</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;listener:&nbsp;<a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.PagedListListener.html">AsyncPagedListDiffer.PagedListListener</a>&lt;T&gt;<br>)</code></div>
<p>Add a <code><a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.PagedListListener.html">PagedListListener</a></code> to receive updates when the current <code><a href="/reference/kotlin/androidx/paging/PagedList.html">PagedList</a></code> changes.</p>
</td>
</tr>
<tr>
<td><code><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a></code></td>
<td width="100%">
<div><code><a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.html#addPagedListListener(kotlin.Function2)">addPagedListListener</a>(callback:&nbsp;(<a href="/reference/kotlin/androidx/paging/PagedList.html">PagedList</a>&lt;T&gt;?,&nbsp;<a href="/reference/kotlin/androidx/paging/PagedList.html">PagedList</a>&lt;T&gt;?)&nbsp;-&gt;&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a>)</code></div>
<p>Add a callback to receive updates when the current <code><a href="/reference/kotlin/androidx/paging/PagedList.html">PagedList</a></code> changes.</p>
</td>
</tr>
<tr>
<td><code>open T?</code></td>
<td width="100%">
<div><code><a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.html#getItem(kotlin.Int)">getItem</a>(index:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html">Int</a>)</code></div>
<p>Get the item from the current PagedList at the specified index.</p>
</td>
</tr>
<tr>
<td><code>open <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a></code></td>
<td width="100%">
<div><code><a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.html#removeLoadStateListener(kotlin.Function2)">removeLoadStateListener</a>(listener:&nbsp;(<a href="/reference/kotlin/androidx/paging/LoadType.html">LoadType</a>,&nbsp;<a href="/reference/kotlin/androidx/paging/LoadState.html">LoadState</a>)&nbsp;-&gt;&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a>)</code></div>
<p>Remove a previously registered <code><a href="/reference/kotlin/androidx/paging/LoadState.html">LoadState</a></code> listener.</p>
</td>
</tr>
<tr>
<td><code>open <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a></code></td>
<td width="100%">
<div><code><a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.html#removePagedListListener(androidx.paging.AsyncPagedListDiffer.PagedListListener)">removePagedListListener</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;listener:&nbsp;<a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.PagedListListener.html">AsyncPagedListDiffer.PagedListListener</a>&lt;T&gt;<br>)</code></div>
<p>Remove a previously registered <code><a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.PagedListListener.html">PagedListListener</a></code>.</p>
</td>
</tr>
<tr>
<td><code><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a></code></td>
<td width="100%">
<div><code><a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.html#removePagedListListener(kotlin.Function2)">removePagedListListener</a>(callback:&nbsp;(<a href="/reference/kotlin/androidx/paging/PagedList.html">PagedList</a>&lt;T&gt;?,&nbsp;<a href="/reference/kotlin/androidx/paging/PagedList.html">PagedList</a>&lt;T&gt;?)&nbsp;-&gt;&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a>)</code></div>
<p>Remove a previously registered callback via <code><a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.html#addPagedListListener(androidx.paging.AsyncPagedListDiffer.PagedListListener)">addPagedListListener</a></code>.</p>
</td>
</tr>
<tr>
<td><code>open <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a></code></td>
<td width="100%">
<div><code><a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.html#submitList(androidx.paging.PagedList)">submitList</a>(pagedList:&nbsp;<a href="/reference/kotlin/androidx/paging/PagedList.html">PagedList</a>&lt;T&gt;?)</code></div>
<p>Pass a new <code><a href="/reference/kotlin/androidx/paging/PagedList.html">PagedList</a></code> to the differ.</p>
</td>
</tr>
<tr>
<td><code>open <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a></code></td>
<td width="100%">
<div><code><a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.html#submitList(androidx.paging.PagedList,java.lang.Runnable)">submitList</a>(pagedList:&nbsp;<a href="/reference/kotlin/androidx/paging/PagedList.html">PagedList</a>&lt;T&gt;?,&nbsp;commitCallback:&nbsp;<a href="https://developer.android.com/reference/java/lang/Runnable.html">Runnable</a>?)</code></div>
<p>Pass a new PagedList to the differ.</p>
</td>
</tr>
</tbody>
</table>
</div>
<h2>Public properties</h2>
<div><a name="getCurrentList()"></a><a name="setCurrentList()"></a><a name="getCurrentList--"></a><a name="setCurrentList--"></a>
<h3 class="api-name" id="currentList()">currentList</h3>
<pre class="api-signature no-pretty-print">open&nbsp;val&nbsp;<a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.html#currentList()">currentList</a>:&nbsp;<a href="/reference/kotlin/androidx/paging/PagedList.html">PagedList</a>&lt;T&gt;?</pre>
<p>Returns the PagedList currently being displayed by the differ.</p>
<p>This is not necessarily the most recent list passed to <code><a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.html#submitList(androidx.paging.PagedList)">submitList</a></code>, because a diff is computed asynchronously between the new list and the current list before updating the currentList value. May be <code>null</code> if no <code><a href="/reference/kotlin/androidx/paging/PagedList.html">PagedList</a></code> is being presented.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2">Returns</th>
</tr>
</thead>
<tbody>
<tr>
<td><code><a href="/reference/kotlin/androidx/paging/PagedList.html">PagedList</a>&lt;T&gt;?</code></td>
<td width="100%">
<p>The list currently being displayed, may be <code>null</code>.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div><a name="getItemCount()"></a><a name="setItemCount()"></a><a name="getItemCount--"></a><a name="setItemCount--"></a>
<h3 class="api-name" id="itemCount()">itemCount</h3>
<pre class="api-signature no-pretty-print">open&nbsp;val&nbsp;<a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.html#itemCount()">itemCount</a>:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html">Int</a></pre>
<p>Get the number of items currently presented by this Differ. This value can be directly returned to <a href="[RecyclerView.Adapter.getItemCount]">RecyclerView.Adapter.getItemCount</a>.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2">Returns</th>
</tr>
</thead>
<tbody>
<tr>
<td><code><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html">Int</a></code></td>
<td width="100%">
<p>Number of items being presented.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<h2>Public constructors</h2>
<div><a name="AsyncPagedListDiffer(RecyclerView.Adapter&lt;*&gt;, DiffUtil.ItemCallback&lt;T&gt;)"></a><a name="AsyncPagedListDiffer-RecyclerView.Adapter&lt;*&gt;-DiffUtil.ItemCallback&lt;T&gt;-"></a>
<h3 class="api-name" id="AsyncPagedListDiffer(RecyclerView.Adapter&lt;*&gt;,DiffUtil.ItemCallback&lt;T&gt;)">AsyncPagedListDiffer</h3>
<pre class="api-signature no-pretty-print">&lt;T&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>&gt; <span><del><a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.html#AsyncPagedListDiffer(RecyclerView.Adapter&lt;*&gt;,DiffUtil.ItemCallback&lt;T&gt;)">AsyncPagedListDiffer</a></del></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;adapter:&nbsp;<a href="/reference/kotlin/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>&lt;<a href="/reference/kotlin/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;diffCallback:&nbsp;<a href="/reference/kotlin/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>&lt;T&gt;<br>)</pre>
<aside class="caution"><strong>This function is deprecated.</strong><br>PagedList is deprecated and has been replaced by PagingData</aside>
<p>Convenience for</p>
<pre class="prettyprint">AsyncPagedListDiffer(<br> AdapterListUpdateCallback(adapter),<br> AsyncDifferConfig.Builder&lt;T&gt;(diffCallback).build()<br>)</pre>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2">Parameters</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>adapter:&nbsp;<a href="/reference/kotlin/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>&lt;<a href="/reference/kotlin/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>&gt;</code></td>
<td width="100%">
<p>Adapter that will receive update signals.</p>
</td>
</tr>
<tr>
<td><code>diffCallback:&nbsp;<a href="/reference/kotlin/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>&lt;T&gt;</code></td>
<td width="100%">
<p>The <a href="[DiffUtil.ItemCallback]">DiffUtil.ItemCallback</a> instance to compare items in the list.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div><a name="AsyncPagedListDiffer(ListUpdateCallback, AsyncDifferConfig&lt;T&gt;)"></a><a name="AsyncPagedListDiffer-ListUpdateCallback-AsyncDifferConfig&lt;T&gt;-"></a>
<h3 class="api-name" id="AsyncPagedListDiffer(ListUpdateCallback,AsyncDifferConfig&lt;T&gt;)">AsyncPagedListDiffer</h3>
<pre class="api-signature no-pretty-print">&lt;T&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>&gt; <span><del><a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.html#AsyncPagedListDiffer(ListUpdateCallback,AsyncDifferConfig&lt;T&gt;)">AsyncPagedListDiffer</a></del></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;listUpdateCallback:&nbsp;<a href="/reference/kotlin/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;config:&nbsp;<a href="/reference/kotlin/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>&lt;T&gt;<br>)</pre>
<aside class="caution"><strong>This function is deprecated.</strong><br>PagedList is deprecated and has been replaced by PagingData</aside>
</div>
<h2>Public functions</h2>
<div><a name="addLoadStateListener-kotlin.Function2-"></a>
<h3 class="api-name" id="addLoadStateListener(kotlin.Function2)">addLoadStateListener</h3>
<pre class="api-signature no-pretty-print">open&nbsp;fun&nbsp;<a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.html#addLoadStateListener(kotlin.Function2)">addLoadStateListener</a>(listener:&nbsp;(<a href="/reference/kotlin/androidx/paging/LoadType.html">LoadType</a>,&nbsp;<a href="/reference/kotlin/androidx/paging/LoadState.html">LoadState</a>)&nbsp;-&gt;&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a>):&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a></pre>
<p>Add a <code><a href="/reference/kotlin/androidx/paging/LoadState.html">LoadState</a></code> listener to observe the loading state of the current <code><a href="/reference/kotlin/androidx/paging/PagedList.html">PagedList</a></code>.</p>
<p>As new PagedLists are submitted and displayed, the listener will be notified to reflect current <code><a href="/reference/kotlin/androidx/paging/LoadType.REFRESH.html">LoadType.REFRESH</a></code>, <code><a href="/reference/kotlin/androidx/paging/LoadType.PREPEND.html">LoadType.PREPEND</a></code>, and <code><a href="/reference/kotlin/androidx/paging/LoadType.APPEND.html">LoadType.APPEND</a></code> states.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2">Parameters</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>listener:&nbsp;(<a href="/reference/kotlin/androidx/paging/LoadType.html">LoadType</a>,&nbsp;<a href="/reference/kotlin/androidx/paging/LoadState.html">LoadState</a>)&nbsp;-&gt;&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a></code></td>
<td width="100%">
<p><code><a href="/reference/kotlin/androidx/paging/LoadState.html">LoadState</a></code> listener to receive updates.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2">See also</th>
</tr>
</thead>
<tbody>
<tr>
<td><code><a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.html#removeLoadStateListener(kotlin.Function2)">removeLoadStateListener</a></code></td>
<td width="100%"></td>
</tr>
</tbody>
</table>
</div>
</div>
<div><a name="addPagedListListener-androidx.paging.AsyncPagedListDiffer.PagedListListener-"></a>
<h3 class="api-name" id="addPagedListListener(androidx.paging.AsyncPagedListDiffer.PagedListListener)">addPagedListListener</h3>
<pre class="api-signature no-pretty-print">open&nbsp;fun&nbsp;<a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.html#addPagedListListener(androidx.paging.AsyncPagedListDiffer.PagedListListener)">addPagedListListener</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;listener:&nbsp;<a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.PagedListListener.html">AsyncPagedListDiffer.PagedListListener</a>&lt;T&gt;<br>):&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a></pre>
<p>Add a <code><a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.PagedListListener.html">PagedListListener</a></code> to receive updates when the current <code><a href="/reference/kotlin/androidx/paging/PagedList.html">PagedList</a></code> changes.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2">Parameters</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>listener:&nbsp;<a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.PagedListListener.html">AsyncPagedListDiffer.PagedListListener</a>&lt;T&gt;</code></td>
<td width="100%">
<p>Listener to receive updates.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2">See also</th>
</tr>
</thead>
<tbody>
<tr>
<td><code><a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.html#currentList()">currentList</a></code></td>
<td width="100%"></td>
</tr>
<tr>
<td><code><a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.html#removePagedListListener(androidx.paging.AsyncPagedListDiffer.PagedListListener)">removePagedListListener</a></code></td>
<td width="100%"></td>
</tr>
</tbody>
</table>
</div>
</div>
<div><a name="addPagedListListener-kotlin.Function2-"></a>
<h3 class="api-name" id="addPagedListListener(kotlin.Function2)">addPagedListListener</h3>
<pre class="api-signature no-pretty-print">fun&nbsp;<a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.html#addPagedListListener(kotlin.Function2)">addPagedListListener</a>(callback:&nbsp;(<a href="/reference/kotlin/androidx/paging/PagedList.html">PagedList</a>&lt;T&gt;?,&nbsp;<a href="/reference/kotlin/androidx/paging/PagedList.html">PagedList</a>&lt;T&gt;?)&nbsp;-&gt;&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a>):&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a></pre>
<p>Add a callback to receive updates when the current <code><a href="/reference/kotlin/androidx/paging/PagedList.html">PagedList</a></code> changes.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2">Parameters</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>callback:&nbsp;(<a href="/reference/kotlin/androidx/paging/PagedList.html">PagedList</a>&lt;T&gt;?,&nbsp;<a href="/reference/kotlin/androidx/paging/PagedList.html">PagedList</a>&lt;T&gt;?)&nbsp;-&gt;&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a></code></td>
<td width="100%">
<p>to receive updates.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2">See also</th>
</tr>
</thead>
<tbody>
<tr>
<td><code><a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.html#currentList()">currentList</a></code></td>
<td width="100%"></td>
</tr>
<tr>
<td><code><a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.html#removePagedListListener(androidx.paging.AsyncPagedListDiffer.PagedListListener)">removePagedListListener</a></code></td>
<td width="100%"></td>
</tr>
</tbody>
</table>
</div>
</div>
<div><a name="getItem-kotlin.Int-"></a>
<h3 class="api-name" id="getItem(kotlin.Int)">getItem</h3>
<pre class="api-signature no-pretty-print">open&nbsp;fun&nbsp;<a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.html#getItem(kotlin.Int)">getItem</a>(index:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html">Int</a>):&nbsp;T?</pre>
<p>Get the item from the current PagedList at the specified index.</p>
<p>Note that this operates on both loaded items and null padding within the PagedList.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2">Returns</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>T?</code></td>
<td width="100%">
<p>The item, or null, if a null placeholder is at the specified position.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2">Parameters</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>index:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html">Int</a></code></td>
<td width="100%">
<p>Index of item to get, must be &gt;= 0, and &lt; <code>getItemCount</code>.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2">Throws</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>kotlin.IndexOutOfBoundsException</code></td>
<td width="100%">
<p>if <code><a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.html#itemCount()">itemCount</a></code> is 0.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div><a name="removeLoadStateListener-kotlin.Function2-"></a>
<h3 class="api-name" id="removeLoadStateListener(kotlin.Function2)">removeLoadStateListener</h3>
<pre class="api-signature no-pretty-print">open&nbsp;fun&nbsp;<a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.html#removeLoadStateListener(kotlin.Function2)">removeLoadStateListener</a>(listener:&nbsp;(<a href="/reference/kotlin/androidx/paging/LoadType.html">LoadType</a>,&nbsp;<a href="/reference/kotlin/androidx/paging/LoadState.html">LoadState</a>)&nbsp;-&gt;&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a>):&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a></pre>
<p>Remove a previously registered <code><a href="/reference/kotlin/androidx/paging/LoadState.html">LoadState</a></code> listener.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2">Parameters</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>listener:&nbsp;(<a href="/reference/kotlin/androidx/paging/LoadType.html">LoadType</a>,&nbsp;<a href="/reference/kotlin/androidx/paging/LoadState.html">LoadState</a>)&nbsp;-&gt;&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a></code></td>
<td width="100%">
<p>Previously registered listener.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2">See also</th>
</tr>
</thead>
<tbody>
<tr>
<td><code><a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.html#currentList()">currentList</a></code></td>
<td width="100%"></td>
</tr>
<tr>
<td><code><a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.html#addPagedListListener(androidx.paging.AsyncPagedListDiffer.PagedListListener)">addPagedListListener</a></code></td>
<td width="100%"></td>
</tr>
</tbody>
</table>
</div>
</div>
<div><a name="removePagedListListener-androidx.paging.AsyncPagedListDiffer.PagedListListener-"></a>
<h3 class="api-name" id="removePagedListListener(androidx.paging.AsyncPagedListDiffer.PagedListListener)">removePagedListListener</h3>
<pre class="api-signature no-pretty-print">open&nbsp;fun&nbsp;<a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.html#removePagedListListener(androidx.paging.AsyncPagedListDiffer.PagedListListener)">removePagedListListener</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;listener:&nbsp;<a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.PagedListListener.html">AsyncPagedListDiffer.PagedListListener</a>&lt;T&gt;<br>):&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a></pre>
<p>Remove a previously registered <code><a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.PagedListListener.html">PagedListListener</a></code>.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2">Parameters</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>listener:&nbsp;<a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.PagedListListener.html">AsyncPagedListDiffer.PagedListListener</a>&lt;T&gt;</code></td>
<td width="100%">
<p>Previously registered listener.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2">See also</th>
</tr>
</thead>
<tbody>
<tr>
<td><code><a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.html#currentList()">currentList</a></code></td>
<td width="100%"></td>
</tr>
<tr>
<td><code><a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.html#addPagedListListener(androidx.paging.AsyncPagedListDiffer.PagedListListener)">addPagedListListener</a></code></td>
<td width="100%"></td>
</tr>
</tbody>
</table>
</div>
</div>
<div><a name="removePagedListListener-kotlin.Function2-"></a>
<h3 class="api-name" id="removePagedListListener(kotlin.Function2)">removePagedListListener</h3>
<pre class="api-signature no-pretty-print">fun&nbsp;<a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.html#removePagedListListener(kotlin.Function2)">removePagedListListener</a>(callback:&nbsp;(<a href="/reference/kotlin/androidx/paging/PagedList.html">PagedList</a>&lt;T&gt;?,&nbsp;<a href="/reference/kotlin/androidx/paging/PagedList.html">PagedList</a>&lt;T&gt;?)&nbsp;-&gt;&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a>):&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a></pre>
<p>Remove a previously registered callback via <code><a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.html#addPagedListListener(androidx.paging.AsyncPagedListDiffer.PagedListListener)">addPagedListListener</a></code>.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2">Parameters</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>callback:&nbsp;(<a href="/reference/kotlin/androidx/paging/PagedList.html">PagedList</a>&lt;T&gt;?,&nbsp;<a href="/reference/kotlin/androidx/paging/PagedList.html">PagedList</a>&lt;T&gt;?)&nbsp;-&gt;&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a></code></td>
<td width="100%">
<p>Previously registered callback.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2">See also</th>
</tr>
</thead>
<tbody>
<tr>
<td><code><a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.html#currentList()">currentList</a></code></td>
<td width="100%"></td>
</tr>
<tr>
<td><code><a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.html#addPagedListListener(androidx.paging.AsyncPagedListDiffer.PagedListListener)">addPagedListListener</a></code></td>
<td width="100%"></td>
</tr>
</tbody>
</table>
</div>
</div>
<div><a name="submitList-androidx.paging.PagedList-"></a>
<h3 class="api-name" id="submitList(androidx.paging.PagedList)">submitList</h3>
<pre class="api-signature no-pretty-print">open&nbsp;fun&nbsp;<a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.html#submitList(androidx.paging.PagedList)">submitList</a>(pagedList:&nbsp;<a href="/reference/kotlin/androidx/paging/PagedList.html">PagedList</a>&lt;T&gt;?):&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a></pre>
<p>Pass a new <code><a href="/reference/kotlin/androidx/paging/PagedList.html">PagedList</a></code> to the differ.</p>
<p>If a PagedList is already present, a diff will be computed asynchronously on a background thread. When the diff is computed, it will be applied (dispatched to the <a href="[ListUpdateCallback]">ListUpdateCallback</a>), and the new PagedList will be swapped in as the <code><a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.html#currentList()">currentList</a></code>.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2">Parameters</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>pagedList:&nbsp;<a href="/reference/kotlin/androidx/paging/PagedList.html">PagedList</a>&lt;T&gt;?</code></td>
<td width="100%">
<p>The new PagedList.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div><a name="submitList(androidx.paging.PagedList, java.lang.Runnable)"></a><a name="submitList-androidx.paging.PagedList-java.lang.Runnable-"></a>
<h3 class="api-name" id="submitList(androidx.paging.PagedList,java.lang.Runnable)">submitList</h3>
<pre class="api-signature no-pretty-print">open&nbsp;fun&nbsp;<a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.html#submitList(androidx.paging.PagedList,java.lang.Runnable)">submitList</a>(pagedList:&nbsp;<a href="/reference/kotlin/androidx/paging/PagedList.html">PagedList</a>&lt;T&gt;?,&nbsp;commitCallback:&nbsp;<a href="https://developer.android.com/reference/java/lang/Runnable.html">Runnable</a>?):&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a></pre>
<p>Pass a new PagedList to the differ.</p>
<p>If a PagedList is already present, a diff will be computed asynchronously on a background thread. When the diff is computed, it will be applied (dispatched to the <a href="[ListUpdateCallback]">ListUpdateCallback</a>), and the new PagedList will be swapped in as the <code><a href="/reference/kotlin/androidx/paging/AsyncPagedListDiffer.html#currentList()">current list</a></code>.</p>
<p>The commit callback can be used to know when the PagedList is committed, but note that it may not be executed. If PagedList B is submitted immediately after PagedList A, and is committed directly, the callback associated with PagedList A will not be run.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2">Parameters</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>pagedList:&nbsp;<a href="/reference/kotlin/androidx/paging/PagedList.html">PagedList</a>&lt;T&gt;?</code></td>
<td width="100%">
<p>The new <code><a href="/reference/kotlin/androidx/paging/PagedList.html">PagedList</a></code>.</p>
</td>
</tr>
<tr>
<td><code>commitCallback:&nbsp;<a href="https://developer.android.com/reference/java/lang/Runnable.html">Runnable</a>?</code></td>
<td width="100%">
<p>Optional runnable that is executed when the PagedList is committed, if it is committed.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2">Throws</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>kotlin.IllegalStateException</code></td>
<td width="100%">
<p>if previous PagedList wasn't snapshotted correctly.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>