With lazy loading and Paging, you can support large lists of items—including an infinite list—in your app by loading and displaying data incrementally. This technique enables you to reduce initial load times and optimize memory usage, enhancing performance.
Version compatibility
This implementation requires that your project minSDK be set to API level 21 or higher.
Dependencies
Display paged content
With the Paging library, you can load and display pages of data from a larger dataset acquired from local storage or over a network. Use the following code to display a paginated list that shows a progress bar to indicate to the user that more data is being fetched:
Key points about the code
LazyColumn
: This composable is used to display a large list of items (messages) efficiently. It only renders the items that are visible on the screen, thus saving resources and memory.- The
lazyPagingItems
object efficiently manages the loading and presentation of paged data within theLazyColumn
. It passesLazyPagingItems
toitems
in theLazyColumn
composable. MessageRow(message: Text)
is responsible for rendering individual message items, likely displaying the sender and text of the message within a Card.MessagePlaceholder()
provides a visual placeholder (a loading spinner) while the actual message data is being fetched, enhancing the user experience.
Results
![A large list fetching data as the user scrolls](https://developer.android.google.cn/static/quick-guides/content/lazy-loading.gif?authuser=6)
Parent collections
![](https://developer.android.google.cn/static/images/quick-guides/collection-illustration.png?authuser=6)
Display a list or grid
Lists and grids allow your app to display collections in a
visually pleasing form that's easy for users to consume.
![](https://developer.android.google.cn/static/images/quick-guides/collection-illustration.png?authuser=6)
Display interactive components
Learn how composable functions can enable you to easily
create beautiful UI components based on the Material Design design
system.
![](https://developer.android.google.cn/static/images/quick-guides/collection-illustration.png?authuser=6)
Compose basics (video collection)
This series of videos introduces various Compose APIs,
quickly showing you what’s available and how to use them.
Have questions or feedback
Go to our frequently asked questions page and learn about quick guides or reach out and let us know your thoughts.