auto pagination if using recyclerview inside NestedSrollView with Paging 3?

Viewed 266

I'm using recyclerview inside nestedscrollview to scroll in the full page size but that ruined the pagination functionality because it auto loads all the pages without user scrolling.

here is my xml layout

<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<View android:id="@+id/header_view"
android:layout_width="0dp"
android:layout_height="300dp"
android:layout_marginTop="21dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

 <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/picked_up_rv"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_marginTop="16dp"
                android:paddingBottom="8dp"
                app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/header_view" />

</androidx.constraintlayout.widget.ConstraintLayout>

And I'm using Paging 3 for pagination

implementation "androidx.paging:paging-runtime-ktx:3.1.0"
1 Answers

Inside the Paging3 library, you can define a LoadStateAdapter and attach it to your PagingDataAdapter, then you can attach footer and header views directly.

If you don't want to use the LoadStateAdapter, then you can create differents items for your PagingDataAdapter and then use item view type to retrieve what you want. With this method you get rid of your NestedScrollView which is useless since RecyclerView implements ScrollingView

Related