I'm using Android Paging 3 library. In my testing configuration it has a PagingConfig
with pageSize = 10
and maxSize = 40
. When I scroll down the configured RecyclerView
, everything works as expected - new portions of data are loaded when I'm getting close to the lower bound of the list. When we have too many data items loaded (more than the configured maxSize
), it begins to be dropped - and it's an expected behaviour. But when I begin to scroll up, there are empty view holders without any data for these dropped items. That means the count of adapter's items doesn't change on the clean up of PagingData
. How can I remove these dropped items (which are equal to null
) from the PagingDataAdapter
? Is there any API for this? If it should be done automatically, then my configuration of Paging 3 may be wrong. In this case I'll provide the code.
Asked
Active
Viewed 1,437 times
0

Andrei K.
- 534
- 7
- 20
-
Looks like my configuration is correct - the official codelab for Paging 3 library does the same (null data models for dropped items) if we configure `maxSize` for it... – Andrei K. Jul 15 '20 at 14:25
-
And the same thing for PagingWithNetworkSample from architecture-components-samples repo. Looks like the best thing I can do for now - is to disable `maxSize` restriction. – Andrei K. Jul 15 '20 at 15:26
-
Looks like `retry()` method in `PagingDataAdapter` doesn't work too. There is no reaction when I call it after failed page fetching. Will use `refresh()` for now... – Andrei K. Jul 16 '20 at 11:31
1 Answers
0
Do you have PagingConfig.enablePlaceholders
set?
Disabling placeholders will prevent Paging from padding your lists with null
items for pages that haven't loaded yet.
The default value for PagingConfig.enablePlaceholders
is true
.
Edit: While the above comment still holds since placeholders are represented as null
items, this was actually a bug in alpha02, which has since been fixed and will go out with alpha03.

dlam
- 3,547
- 17
- 20
-
-
Moreover setting `PagingConfig.enablePlaceholders` to `false` didn't change the described behaviour in PagingWithNetworkSample - checked right now – Andrei K. Jul 15 '20 at 16:03
-
Step to reproduce: fetching the architecture-components-samples repo -> opening PagingWithNetworkSample project -> setting `maxSize = 90, enablePlaceholders = false` in `InMemoryByPageKeyRepository` -> running the app, scrolling more than 90 items to bottom -> scrolling to top again - there are empty items in forever "loading" state – Andrei K. Jul 15 '20 at 16:11
-
Thanks, if what you're saying is true this is a bug on Paging's end. I tried to reproduce the issue here, but didn't succeed: https://github.com/dlam/architecture-components-samples/tree/so/62909698 I'm logging the result of the first item the adapter can present after each append. Either way, I've filed an issue here: https://issuetracker.google.com/161475289 to track progress on this and would be happy to re-open if you could upload a repro! – dlam Jul 17 '20 at 01:53
-
Note that I'm logging on APPEND in loadStateFlow as those events are guaranteed to be synchronous with adapter updates (there is an existing issue with initial load though). – dlam Jul 17 '20 at 01:54
-
1My mistake - although disabling placeholders is still required to remove nulls (nulls are placeholders), I realized that this was actually a bug in alpha02 I fixed quite awhile ago. It will go out with alpha03 - https://android-review.googlesource.com/c/platform/frameworks/support/+/1350887 – dlam Jul 17 '20 at 21:36