blob: 6e0ccc4fa9a62287fade3caa1eeaa30d1977a4cd [file] [log] [blame]
<html devsite="true">
<head>
<title>LoadStateAdapter</title>
{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %}
{% include "_shared/_reference-head-tags.html" %}
</head>
<body>
<h1>LoadStateAdapter</h1>
{% setvar page_path %}androidx/paging/LoadStateAdapter.html{% endsetvar %}
{% setvar can_switch %}1{% endsetvar %}
{% include "reference/_java_switcher2.md" %}
<p>
<pre>public abstract class LoadStateAdapter&lt;VH&nbsp;extends&nbsp;@<a href="/reference/androidx/annotation/Nullable.html">Nullable</a>&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&gt;</pre>
</p>
<hr>
<p>Adapter for displaying a RecyclerView item based on <code><a href="/reference/androidx/paging/LoadState.html">LoadState</a></code>, such as a loading spinner, or a retry error button.</p>
<p>By default will use one shared <a href="[RecyclerView.Adapter.getItemViewType]">RecyclerView.Adapter.getItemViewType</a> for all items.</p>
<p>By default, both <code><a href="/reference/androidx/paging/LoadState.Loading.html">LoadState.Loading</a></code> and <code><a href="/reference/androidx/paging/LoadState.Error.html">LoadState.Error</a></code> are presented as adapter items, other states are not. To configure this, override <code><a href="/reference/androidx/paging/LoadStateAdapter.html#displayLoadStateAsItem(androidx.paging.LoadState)">displayLoadStateAsItem</a></code>.</p>
<p>To present this Adapter as a header and or footer alongside your <code><a href="/reference/androidx/paging/PagingDataAdapter.html">PagingDataAdapter</a></code>, see <code><a href="/reference/androidx/paging/PagingDataAdapter.html#withLoadStateHeaderAndFooter(androidx.paging.LoadStateAdapter,androidx.paging.LoadStateAdapter)">PagingDataAdapter.withLoadStateHeaderAndFooter</a></code>, or use <a href="[androidx.recyclerview.widget.ConcatAdapter]">androidx.recyclerview.widget.ConcatAdapter</a> directly to concatenate Adapters.</p>
<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/androidx/paging/PagingDataAdapter.html#withLoadStateHeaderAndFooter(androidx.paging.LoadStateAdapter,androidx.paging.LoadStateAdapter)">withLoadStateHeaderAndFooter</a></code></td>
<td width="100%"></td>
</tr>
<tr>
<td><code><a href="/reference/androidx/paging/PagingDataAdapter.html#withLoadStateHeader(androidx.paging.LoadStateAdapter)">withLoadStateHeader</a></code></td>
<td width="100%"></td>
</tr>
<tr>
<td><code><a href="/reference/androidx/paging/PagingDataAdapter.html#withLoadStateFooter(androidx.paging.LoadStateAdapter)">withLoadStateFooter</a></code></td>
<td width="100%"></td>
</tr>
</tbody>
</table>
</div>
<h2>Summary</h2>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2"><h3>Public fields</h3></th>
</tr>
</thead>
<tbody>
<tr>
<td><code>final <a href="/reference/androidx/paging/LoadState.html">LoadState</a></code></td>
<td width="100%">
<div><code><a href="/reference/androidx/paging/LoadStateAdapter.html#loadState()">loadState</a></code></div>
<p>LoadState to present in the adapter.</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;VH&nbsp;extends&nbsp;@<a href="/reference/androidx/annotation/Nullable.html">Nullable</a>&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&gt; <a href="/reference/androidx/paging/LoadStateAdapter.html#LoadStateAdapter()">LoadStateAdapter</a>()</code></div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2"><h3>Public methods</h3></th>
</tr>
</thead>
<tbody>
<tr>
<td><code>boolean</code></td>
<td width="100%">
<div><code><a href="/reference/androidx/paging/LoadStateAdapter.html#displayLoadStateAsItem(androidx.paging.LoadState)">displayLoadStateAsItem</a>(<a href="/reference/androidx/paging/LoadState.html">LoadState</a>&nbsp;loadState)</code></div>
<p>Returns true if the LoadState should be displayed as a list item when active.</p>
</td>
</tr>
<tr>
<td><code>final int</code></td>
<td width="100%">
<div><code><a href="/reference/androidx/paging/LoadStateAdapter.html#getItemCount()">getItemCount</a>()</code></div>
</td>
</tr>
<tr>
<td><code>final int</code></td>
<td width="100%">
<div><code><a href="/reference/androidx/paging/LoadStateAdapter.html#getItemViewType(kotlin.Int)">getItemViewType</a>(int&nbsp;position)</code></div>
</td>
</tr>
<tr>
<td><code>int</code></td>
<td width="100%">
<div><code><a href="/reference/androidx/paging/LoadStateAdapter.html#getStateViewType(androidx.paging.LoadState)">getStateViewType</a>(<a href="/reference/androidx/paging/LoadState.html">LoadState</a>&nbsp;loadState)</code></div>
<p>Override this method to use different view types per LoadState.</p>
</td>
</tr>
<tr>
<td><code>final void</code></td>
<td width="100%">
<div><code><a href="/reference/androidx/paging/LoadStateAdapter.html#onBindViewHolder(kotlin.Any,kotlin.Int)">onBindViewHolder</a>(VH&nbsp;holder,&nbsp;int&nbsp;position)</code></div>
</td>
</tr>
<tr>
<td><code>abstract void</code></td>
<td width="100%">
<div><code><a href="/reference/androidx/paging/LoadStateAdapter.html#onBindViewHolder(kotlin.Any,androidx.paging.LoadState)">onBindViewHolder</a>(VH&nbsp;holder,&nbsp;<a href="/reference/androidx/paging/LoadState.html">LoadState</a>&nbsp;loadState)</code></div>
<p>Called to bind the passed LoadState to the ViewHolder.</p>
</td>
</tr>
<tr>
<td><code>final VH</code></td>
<td width="100%">
<div><code><a href="/reference/androidx/paging/LoadStateAdapter.html#onCreateViewHolder(ViewGroup,kotlin.Int)">onCreateViewHolder</a>(<a href="/reference/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>&nbsp;parent,&nbsp;int&nbsp;viewType)</code></div>
</td>
</tr>
<tr>
<td><code>abstract VH</code></td>
<td width="100%">
<div><code><a href="/reference/androidx/paging/LoadStateAdapter.html#onCreateViewHolder(ViewGroup,androidx.paging.LoadState)">onCreateViewHolder</a>(<a href="/reference/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>&nbsp;parent,&nbsp;<a href="/reference/androidx/paging/LoadState.html">LoadState</a>&nbsp;loadState)</code></div>
<p>Called to create a ViewHolder for the given LoadState.</p>
</td>
</tr>
</tbody>
</table>
</div>
<h2>Public fields</h2>
<div><a name="getLoadState()"></a><a name="setLoadState()"></a><a name="getLoadState--"></a><a name="setLoadState--"></a>
<h3 class="api-name" id="loadState()">loadState</h3>
<pre class="api-signature no-pretty-print">public&nbsp;final&nbsp;<a href="/reference/androidx/paging/LoadState.html">LoadState</a>&nbsp;<a href="/reference/androidx/paging/LoadStateAdapter.html#loadState()">loadState</a></pre>
<p>LoadState to present in the adapter.</p>
<p>Changing this property will immediately notify the Adapter to change the item it's presenting.</p>
</div>
<h2>Public constructors</h2>
<div><a name="LoadStateAdapter--"></a>
<h3 class="api-name" id="LoadStateAdapter()">LoadStateAdapter</h3>
<pre class="api-signature no-pretty-print">public&nbsp;final&nbsp;&lt;VH&nbsp;extends&nbsp;@<a href="/reference/androidx/annotation/Nullable.html">Nullable</a>&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&gt; <a href="/reference/androidx/paging/LoadStateAdapter.html#LoadStateAdapter()">LoadStateAdapter</a>()</pre>
</div>
<h2>Public methods</h2>
<div><a name="displayLoadStateAsItem-androidx.paging.LoadState-"></a>
<h3 class="api-name" id="displayLoadStateAsItem(androidx.paging.LoadState)">displayLoadStateAsItem</h3>
<pre class="api-signature no-pretty-print">public&nbsp;boolean&nbsp;<a href="/reference/androidx/paging/LoadStateAdapter.html#displayLoadStateAsItem(androidx.paging.LoadState)">displayLoadStateAsItem</a>(<a href="/reference/androidx/paging/LoadState.html">LoadState</a>&nbsp;loadState)</pre>
<p>Returns true if the LoadState should be displayed as a list item when active.</p>
<p>By default, <code><a href="/reference/androidx/paging/LoadState.Loading.html">LoadState.Loading</a></code> and <code><a href="/reference/androidx/paging/LoadState.Error.html">LoadState.Error</a></code> present as list items, others do not.</p>
</div>
<div><a name="getItemCount--"></a>
<h3 class="api-name" id="getItemCount()">getItemCount</h3>
<pre class="api-signature no-pretty-print">public&nbsp;final&nbsp;int&nbsp;<a href="/reference/androidx/paging/LoadStateAdapter.html#getItemCount()">getItemCount</a>()</pre>
</div>
<div><a name="getItemViewType-kotlin.Int-"></a>
<h3 class="api-name" id="getItemViewType(kotlin.Int)">getItemViewType</h3>
<pre class="api-signature no-pretty-print">public&nbsp;final&nbsp;int&nbsp;<a href="/reference/androidx/paging/LoadStateAdapter.html#getItemViewType(kotlin.Int)">getItemViewType</a>(int&nbsp;position)</pre>
</div>
<div><a name="getStateViewType-androidx.paging.LoadState-"></a>
<h3 class="api-name" id="getStateViewType(androidx.paging.LoadState)">getStateViewType</h3>
<pre class="api-signature no-pretty-print">public&nbsp;int&nbsp;<a href="/reference/androidx/paging/LoadStateAdapter.html#getStateViewType(androidx.paging.LoadState)">getStateViewType</a>(<a href="/reference/androidx/paging/LoadState.html">LoadState</a>&nbsp;loadState)</pre>
<p>Override this method to use different view types per LoadState.</p>
<p>By default, this LoadStateAdapter only uses a single view type.</p>
</div>
<div><a name="onBindViewHolder(kotlin.Any, kotlin.Int)"></a><a name="onBindViewHolder-kotlin.Any-kotlin.Int-"></a>
<h3 class="api-name" id="onBindViewHolder(kotlin.Any,kotlin.Int)">onBindViewHolder</h3>
<pre class="api-signature no-pretty-print">public&nbsp;final&nbsp;void&nbsp;<a href="/reference/androidx/paging/LoadStateAdapter.html#onBindViewHolder(kotlin.Any,kotlin.Int)">onBindViewHolder</a>(VH&nbsp;holder,&nbsp;int&nbsp;position)</pre>
</div>
<div><a name="onBindViewHolder(kotlin.Any, androidx.paging.LoadState)"></a><a name="onBindViewHolder-kotlin.Any-androidx.paging.LoadState-"></a>
<h3 class="api-name" id="onBindViewHolder(kotlin.Any,androidx.paging.LoadState)">onBindViewHolder</h3>
<pre class="api-signature no-pretty-print">public&nbsp;abstract&nbsp;void&nbsp;<a href="/reference/androidx/paging/LoadStateAdapter.html#onBindViewHolder(kotlin.Any,androidx.paging.LoadState)">onBindViewHolder</a>(VH&nbsp;holder,&nbsp;<a href="/reference/androidx/paging/LoadState.html">LoadState</a>&nbsp;loadState)</pre>
<p>Called to bind the passed LoadState to the ViewHolder.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2">Parameters</th>
</tr>
</thead>
<tbody>
<tr>
<td><code><a href="/reference/androidx/paging/LoadState.html">LoadState</a>&nbsp;loadState</code></td>
<td width="100%">
<p>LoadState to display.</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/androidx/paging/LoadStateAdapter.html#getItemViewType(kotlin.Int)">getItemViewType</a></code></td>
<td width="100%"></td>
</tr>
<tr>
<td><code><a href="/reference/androidx/paging/LoadStateAdapter.html#displayLoadStateAsItem(androidx.paging.LoadState)">displayLoadStateAsItem</a></code></td>
<td width="100%"></td>
</tr>
</tbody>
</table>
</div>
</div>
<div><a name="onCreateViewHolder(ViewGroup, kotlin.Int)"></a><a name="onCreateViewHolder-ViewGroup-kotlin.Int-"></a>
<h3 class="api-name" id="onCreateViewHolder(ViewGroup,kotlin.Int)">onCreateViewHolder</h3>
<pre class="api-signature no-pretty-print">public&nbsp;final&nbsp;VH&nbsp;<a href="/reference/androidx/paging/LoadStateAdapter.html#onCreateViewHolder(ViewGroup,kotlin.Int)">onCreateViewHolder</a>(<a href="/reference/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>&nbsp;parent,&nbsp;int&nbsp;viewType)</pre>
</div>
<div><a name="onCreateViewHolder(ViewGroup, androidx.paging.LoadState)"></a><a name="onCreateViewHolder-ViewGroup-androidx.paging.LoadState-"></a>
<h3 class="api-name" id="onCreateViewHolder(ViewGroup,androidx.paging.LoadState)">onCreateViewHolder</h3>
<pre class="api-signature no-pretty-print">public&nbsp;abstract&nbsp;VH&nbsp;<a href="/reference/androidx/paging/LoadStateAdapter.html#onCreateViewHolder(ViewGroup,androidx.paging.LoadState)">onCreateViewHolder</a>(<a href="/reference/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>&nbsp;parent,&nbsp;<a href="/reference/androidx/paging/LoadState.html">LoadState</a>&nbsp;loadState)</pre>
<p>Called to create a ViewHolder for the given LoadState.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2">Parameters</th>
</tr>
</thead>
<tbody>
<tr>
<td><code><a href="/reference/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>&nbsp;parent</code></td>
<td width="100%">
<p>The ViewGroup into which the new View will be added after it is bound to an adapter position.</p>
</td>
</tr>
<tr>
<td><code><a href="/reference/androidx/paging/LoadState.html">LoadState</a>&nbsp;loadState</code></td>
<td width="100%">
<p>The LoadState to be initially presented by the new ViewHolder.</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/androidx/paging/LoadStateAdapter.html#getItemViewType(kotlin.Int)">getItemViewType</a></code></td>
<td width="100%"></td>
</tr>
<tr>
<td><code><a href="/reference/androidx/paging/LoadStateAdapter.html#displayLoadStateAsItem(androidx.paging.LoadState)">displayLoadStateAsItem</a></code></td>
<td width="100%"></td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>