blob: ff20c8c7ecc38280976bd80840a4a10c45acd9d3 [file] [log] [blame]
<html devsite="true">
<head>
<title>LoadStateAdapter</title>
{% setvar book_path %}/reference/kotlin/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/_kotlin_switcher2.md" %}
<p>
<pre>abstract class LoadStateAdapter&lt;VH&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>?&gt;</pre>
</p>
<hr>
<p>Adapter for displaying a RecyclerView item based on <code><a href="/reference/kotlin/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/kotlin/androidx/paging/LoadState.Loading.html">LoadState.Loading</a></code> and <code><a href="/reference/kotlin/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/kotlin/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/kotlin/androidx/paging/PagingDataAdapter.html">PagingDataAdapter</a></code>, see <code><a href="/reference/kotlin/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/kotlin/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/kotlin/androidx/paging/PagingDataAdapter.html#withLoadStateHeader(androidx.paging.LoadStateAdapter)">withLoadStateHeader</a></code></td>
<td width="100%"></td>
</tr>
<tr>
<td><code><a href="/reference/kotlin/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 properties</h3></th>
</tr>
</thead>
<tbody>
<tr>
<td><code><a href="/reference/kotlin/androidx/paging/LoadState.html">LoadState</a></code></td>
<td width="100%">
<div><code><a href="/reference/kotlin/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;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>?&gt; <a href="/reference/kotlin/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 functions</h3></th>
</tr>
</thead>
<tbody>
<tr>
<td><code>open <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html">Boolean</a></code></td>
<td width="100%">
<div><code><a href="/reference/kotlin/androidx/paging/LoadStateAdapter.html#displayLoadStateAsItem(androidx.paging.LoadState)">displayLoadStateAsItem</a>(loadState:&nbsp;<a href="/reference/kotlin/androidx/paging/LoadState.html">LoadState</a>)</code></div>
<p>Returns true if the LoadState should be displayed as a list item when active.</p>
</td>
</tr>
<tr>
<td><code><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/LoadStateAdapter.html#getItemCount()">getItemCount</a>()</code></div>
</td>
</tr>
<tr>
<td><code><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/LoadStateAdapter.html#getItemViewType(kotlin.Int)">getItemViewType</a>(position:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html">Int</a>)</code></div>
</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/LoadStateAdapter.html#getStateViewType(androidx.paging.LoadState)">getStateViewType</a>(loadState:&nbsp;<a href="/reference/kotlin/androidx/paging/LoadState.html">LoadState</a>)</code></div>
<p>Override this method to use different view types per LoadState.</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/LoadStateAdapter.html#onBindViewHolder(kotlin.Any,kotlin.Int)">onBindViewHolder</a>(holder:&nbsp;VH,&nbsp;position:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html">Int</a>)</code></div>
</td>
</tr>
<tr>
<td><code>abstract <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/LoadStateAdapter.html#onBindViewHolder(kotlin.Any,androidx.paging.LoadState)">onBindViewHolder</a>(holder:&nbsp;VH,&nbsp;loadState:&nbsp;<a href="/reference/kotlin/androidx/paging/LoadState.html">LoadState</a>)</code></div>
<p>Called to bind the passed LoadState to the ViewHolder.</p>
</td>
</tr>
<tr>
<td><code>VH</code></td>
<td width="100%">
<div><code><a href="/reference/kotlin/androidx/paging/LoadStateAdapter.html#onCreateViewHolder(,kotlin.Int)">onCreateViewHolder</a>(parent:&nbsp;<a href="/reference/kotlin/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>,&nbsp;viewType:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html">Int</a>)</code></div>
</td>
</tr>
<tr>
<td><code>abstract VH</code></td>
<td width="100%">
<div><code><a href="/reference/kotlin/androidx/paging/LoadStateAdapter.html#onCreateViewHolder(,androidx.paging.LoadState)">onCreateViewHolder</a>(parent:&nbsp;<a href="/reference/kotlin/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>,&nbsp;loadState:&nbsp;<a href="/reference/kotlin/androidx/paging/LoadState.html">LoadState</a>)</code></div>
<p>Called to create a ViewHolder for the given LoadState.</p>
</td>
</tr>
</tbody>
</table>
</div>
<h2>Public properties</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">val&nbsp;<a href="/reference/kotlin/androidx/paging/LoadStateAdapter.html#loadState()">loadState</a>:&nbsp;<a href="/reference/kotlin/androidx/paging/LoadState.html">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">&lt;VH&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>?&gt; <a href="/reference/kotlin/androidx/paging/LoadStateAdapter.html#LoadStateAdapter()">LoadStateAdapter</a>()</pre>
</div>
<h2>Public functions</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">open&nbsp;fun&nbsp;<a href="/reference/kotlin/androidx/paging/LoadStateAdapter.html#displayLoadStateAsItem(androidx.paging.LoadState)">displayLoadStateAsItem</a>(loadState:&nbsp;<a href="/reference/kotlin/androidx/paging/LoadState.html">LoadState</a>):&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html">Boolean</a></pre>
<p>Returns true if the LoadState should be displayed as a list item when active.</p>
<p>By default, <code><a href="/reference/kotlin/androidx/paging/LoadState.Loading.html">LoadState.Loading</a></code> and <code><a href="/reference/kotlin/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">fun&nbsp;<a href="/reference/kotlin/androidx/paging/LoadStateAdapter.html#getItemCount()">getItemCount</a>():&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html">Int</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">fun&nbsp;<a href="/reference/kotlin/androidx/paging/LoadStateAdapter.html#getItemViewType(kotlin.Int)">getItemViewType</a>(position:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html">Int</a>):&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html">Int</a></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">open&nbsp;fun&nbsp;<a href="/reference/kotlin/androidx/paging/LoadStateAdapter.html#getStateViewType(androidx.paging.LoadState)">getStateViewType</a>(loadState:&nbsp;<a href="/reference/kotlin/androidx/paging/LoadState.html">LoadState</a>):&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html">Int</a></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">fun&nbsp;<a href="/reference/kotlin/androidx/paging/LoadStateAdapter.html#onBindViewHolder(kotlin.Any,kotlin.Int)">onBindViewHolder</a>(holder:&nbsp;VH,&nbsp;position:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html">Int</a>):&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a></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">abstract&nbsp;fun&nbsp;<a href="/reference/kotlin/androidx/paging/LoadStateAdapter.html#onBindViewHolder(kotlin.Any,androidx.paging.LoadState)">onBindViewHolder</a>(holder:&nbsp;VH,&nbsp;loadState:&nbsp;<a href="/reference/kotlin/androidx/paging/LoadState.html">LoadState</a>):&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a></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>loadState:&nbsp;<a href="/reference/kotlin/androidx/paging/LoadState.html">LoadState</a></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/kotlin/androidx/paging/LoadStateAdapter.html#getItemViewType(kotlin.Int)">getItemViewType</a></code></td>
<td width="100%"></td>
</tr>
<tr>
<td><code><a href="/reference/kotlin/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(, kotlin.Int)"></a><a name="onCreateViewHolder--kotlin.Int-"></a>
<h3 class="api-name" id="onCreateViewHolder(,kotlin.Int)">onCreateViewHolder</h3>
<pre class="api-signature no-pretty-print">fun&nbsp;<a href="/reference/kotlin/androidx/paging/LoadStateAdapter.html#onCreateViewHolder(,kotlin.Int)">onCreateViewHolder</a>(parent:&nbsp;<a href="/reference/kotlin/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>,&nbsp;viewType:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html">Int</a>):&nbsp;VH</pre>
</div>
<div><a name="onCreateViewHolder(, androidx.paging.LoadState)"></a><a name="onCreateViewHolder--androidx.paging.LoadState-"></a>
<h3 class="api-name" id="onCreateViewHolder(,androidx.paging.LoadState)">onCreateViewHolder</h3>
<pre class="api-signature no-pretty-print">abstract&nbsp;fun&nbsp;<a href="/reference/kotlin/androidx/paging/LoadStateAdapter.html#onCreateViewHolder(,androidx.paging.LoadState)">onCreateViewHolder</a>(parent:&nbsp;<a href="/reference/kotlin/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>,&nbsp;loadState:&nbsp;<a href="/reference/kotlin/androidx/paging/LoadState.html">LoadState</a>):&nbsp;VH</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>parent:&nbsp;<a href="/reference/kotlin/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a></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>loadState:&nbsp;<a href="/reference/kotlin/androidx/paging/LoadState.html">LoadState</a></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/kotlin/androidx/paging/LoadStateAdapter.html#getItemViewType(kotlin.Int)">getItemViewType</a></code></td>
<td width="100%"></td>
</tr>
<tr>
<td><code><a href="/reference/kotlin/androidx/paging/LoadStateAdapter.html#displayLoadStateAsItem(androidx.paging.LoadState)">displayLoadStateAsItem</a></code></td>
<td width="100%"></td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>