Questions tagged [android-paging]

The Paging Architecture Component makes it easier for your app to gradually load information as needed from a data source, without overloading the device or waiting too long for a big database query.

Overview:-

Many apps work with large sets of data, but only need to load and display a small portion of that data at any time. An app might have thousands of items that it could potentially display, but it might only need access to a few dozen of them at once. If the data is stored or synchronized with a remote database, this can also slow the app and waste the user's data plan

While existing Android APIs allowed for paging in content, they came with significant constraints and drawbacks:

  • CursorAdapter makes it easier to map database query results to ListView items.
  • AsyncListUtil allows for paging position-based data into a RecyclerView but doesn't allow for non-positional paging, and it forces nulls-as-placeholders in a countable data set.

Classes:-

The Paging Library provides the following classes, as well as additional supporting classes:

  • DataSource: Use this class to define a data source you need to pull paged data from.
  • PagedList: This class loads data from a DataSource. You can configure how much data is loaded at a time, and how much data should be prefetched, minimizing the amount of time your users have to wait for data to be loaded.
  • PagedListAdapter: This class is an implementation of RecyclerView.Adapter that presents data from a PagedList.
  • LivePagedListProvider: This class generates a LiveData from the DataSource you provide.
524 questions
18
votes
1 answer

Check if the list is empty on the first request in Paging 3.0

I'm trying to check if the first request came with the empty object, to display a layout indicating that it has no item. My solution was to create an exception of my own. I would like to know if there is another better way. Because I looked in the…
OliverDamon
  • 381
  • 3
  • 10
18
votes
4 answers

How to update single item using Paging 3 library

I am trying to find a way to update single item in recycler view using PagingAdapter from Paging 3 library. I have found only one way with PagingAdapter.refresh() method. But this method force to load all list from network. Does anybody know how to…
18
votes
2 answers

Modifying PagedList in Android Paging Architecture library

I'm currently looking into incorporating the Paging Architecture library (version 2.1.0-beta01 at the time of writing) into my app. One components is a list which allows the user to delete individual items from it. This list is network-only and…
18
votes
1 answer

How to correctly scroll after item inserted into PagedListAdapter

I am using the Android Arch PagedListAdapter class. The issue I have run into is that since my app is a chat style app, I need to scroll to position 0 when an item is inserted. But the PagedListAdapter finds the diffs and calls necessary methods on…
Nick Mowen
  • 2,572
  • 2
  • 22
  • 38
17
votes
2 answers

Understanding PagingSource's getRefreshKey

I migrated from Paging 2 to Paging 3 library and now I use the PagingSource to load pages of data from the server. But I have trouble understanding the getRefreshKey method that has to be overriden there. I found some code samples how to implement…
baltekg
  • 985
  • 9
  • 31
15
votes
3 answers

PagedListAdapter.submitList() Behaving Weird When Updating Existing Items

Little story of this topic : the app just updating clicked row's values with dialog when confirmed. Uses pagination scenario on room database. When an item added or removed, the latest dataset is fetched and passed to submitList method, then all…
14
votes
1 answer

Clear `PagingDataAdapter` between refresh calls

I am using the Paging 3 PagingDataAdapter to search the database based on the given query. Every time a new query is submitted, i call the refresh() method on the adapter. The problem is that until the new data is loaded, the old one is still…
baltekg
  • 985
  • 9
  • 31
14
votes
1 answer

onItemAtEndLoaded is called immediately after onZeroItemsLoaded

I have a problem where the method onItemAtEndLoaded is called immediately after onZeroItemsLoaded, the behavior should be only when I finish the scroll. Do you have any idea of what is happening. I can provide my GitHub repo.
José Nobre
  • 4,407
  • 6
  • 20
  • 40
13
votes
1 answer

Restore PagedListAdapter position when resuming activity

I've been experimenting with PagedListAdapter and can't figure out how to restore adapters position correctly. Last attempt was to save lastKey from current list. override fun onSaveInstanceState(outState: Bundle) { …
Martynas Jurkus
  • 9,231
  • 13
  • 59
  • 101
13
votes
1 answer

Paging Library with custom DataSource not updating row on Room update

I have been implementing the new Paging Library with a RecyclerView with an app built on top of the Architecture Components. The data to fill the list is obtained from the Room database. In fact, it is fetched from the network, stored on the local…
13
votes
2 answers

Paging Library without Room

All examples of the new paging library have been with Room library and Room creates a Data Source for us. In my own case, I need to create my custom data source. Here is a method in my view model class that ought to return the live data. My livedata…
Idee
  • 1,887
  • 21
  • 31
12
votes
1 answer

toLiveData not available from DataSource.Factory in Android's Paging

I am trying to use LiveData for paging data from my Room database. The sample code from Google indicates the use of a toLiveData function: class ConcertViewModel(concertDao: ConcertDao) : ViewModel() { val concertList:…
Johann
  • 27,536
  • 39
  • 165
  • 279
12
votes
1 answer

Best way to update a single element using Paging Library

Which is the best way to update a single element when using the new paging library? Let's say we have the Paging with network google sample using the PageKeyedSubredditDataSource. Imagine we want to make a change of a single element of RedditPost.…
11
votes
0 answers

How to disable the auto scroll of a RecyclerView (ListAdapter) that happens when an item is updated?

BACKGROUND I have a UI that shows a list of users' fullnames with a like/dislike button for each item. I am using a ListAdapter that under the hood uses DiffUtil and AsyncListDiffer APIs. The list of users is received as a LiveData from a Room…
11
votes
6 answers

Paging 3 - How to scroll to top of RecyclerView after PagingDataAdapter has finished refreshing AND DiffUtil has finished diffing?

I'm using Paging 3 with RemoteMediator that shows cached data while fetching new data from the network. When I refresh my PagingDataAdapter (by calling refresh() on it) I want my RecyclerView to scroll to the top after the refresh is done. In the…
1
2
3
34 35