3

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"
Amin
  • 463
  • 2
  • 11
  • 29
  • I don't think that you can achieve that; once the the recyclerView is in a scroller view (the same direction), you'll lose the ability of recycling views – Zain Mar 27 '22 at 20:39
  • This is happening to me even when the ```RecyclerView``` is placed inside ```SwipeRefreshLayout```, which implements ```NestedScrollingParent & NestedScrollingChild```. Unable to find a fix for this. – Nataraj KR Oct 14 '22 at 04:56

1 Answers1

0

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

Fcps
  • 335
  • 4
  • 19