classConcertActivity:AppCompatActivity(){privatevaladapter=ConcertAdapter()// Use the 'by viewModels()' Kotlin property delegate// from the activity-ktx artifactprivatevalviewModel:ConcertViewModelbyviewModels()overridefunonCreate(savedInstanceState:Bundle?){super.onCreate(savedInstanceState);viewModel.concerts.observe(this,Observer{adapter.submitList(it)})}}
데이터 소스가 PagedList의 새 인스턴스를 제공하면 활동이 이러한 객체를 어댑터로 보냅니다. PagedListAdapter 구현이 업데이트 계산 방식을 정의하고 페이징과 목록 디핑(Diffing)을 자동으로 처리합니다. 따라서 ViewHolder는 제공된 특정 항목에만 결합되어야 합니다.
Kotlin
classConcertAdapter():PagedListAdapter<Concert,ConcertViewHolder>(DIFF_CALLBACK){overridefunonBindViewHolder(holder:ConcertViewHolder,position:Int){valconcert:Concert? =getItem(position)// Note that "concert" is a placeholder if it's null.holder.bindTo(concert)}companionobject{privatevalDIFF_CALLBACK=...// See Implement the diffing callback section.}}
Java
publicclassConcertAdapterextendsPagedListAdapter<Concert,ConcertViewHolder>{protectedConcertAdapter(){super(DIFF_CALLBACK);}@OverridepublicvoidonBindViewHolder(@NonNullConcertViewHolderholder,intposition){Concertconcert=getItem(position);// Note that "concert" can be null if it's a placeholder.holder.bindTo(concert);}privatestaticDiffUtil.ItemCallback<Concert>DIFF_CALLBACK=...// See Implement the diffing callback section.}
privatevalDIFF_CALLBACK=object:DiffUtil.ItemCallback<Concert>(){// The ID property identifies when items are the same.overridefunareItemsTheSame(oldItem:Concert,newItem:Concert)=oldItem.id==newItem.id// If you use the "==" operator, make sure that the object implements// .equals(). Alternatively, write custom data comparison logic here.overridefunareContentsTheSame(oldItem:Concert,newItem:Concert)=oldItem==newItem}
Java
privatestaticDiffUtil.ItemCallback<Concert>DIFF_CALLBACK=newDiffUtil.ItemCallback<Concert>(){@OverridepublicbooleanareItemsTheSame(ConcertoldItem,ConcertnewItem){// The ID property identifies when items are the same.returnoldItem.getId()==newItem.getId();}@OverridepublicbooleanareContentsTheSame(ConcertoldItem,ConcertnewItem){// Don't use the "==" operator here. Either implement and use .equals(),// or write custom data comparison logic here.returnoldItem.equals(newItem);}};
어댑터에는 비교 항목의 정의가 포함되어 있으므로 새 PagedList 객체가 로드되면 어댑터는 이러한 항목의 변경사항을 자동으로 감지합니다. 결과적으로 어댑터는 RecyclerView 객체 내에서 효율적인 항목 애니메이션을 트리거합니다.
앱이 데이터 가져오기를 완료하기 전에 UI에 목록을 표시하려면 자리표시자 목록 항목을 사용자에게 표시하면 됩니다. PagedList는 데이터가 로드될 때까지 목록 항목 데이터를 null로 표시함으로써 이러한 사례를 처리합니다.
자리표시자 사용 시 다음과 같은 이점이 있습니다.
스크롤바 지원:PagedList가 목록 항목 개수를 PagedListAdapter에 제공합니다. 이 정보를 통해 어댑터는 목록의 전체 크기를 포괄하는 스크롤바를 그릴 수 있습니다. 새 페이지가 로드될 때 목록의 크기가 변경되지 않으므로 스크롤바가 이동하지 않습니다.
로드 중 스피너가 필요하지 않음: 목록 크기가 이미 알려져 있으므로 로드 중인 항목이 더 있음을 사용자에게 알릴 필요가 없습니다. 자리표시자 자체가 이러한 정보를 전달합니다.
그러나 자리표시자에 관한 지원을 추가하기 전에 다음 전제 조건에 유의하세요.
셀 수 있는 데이터 세트 필요:Room 지속성 라이브러리의 DataSource 인스턴스가 항목 수를 효율적으로 계산할 수 있습니다. 그러나 맞춤 로컬 저장소 솔루션 또는 네트워크 전용 데이터 아키텍처를 사용하고 있다면 데이터 세트를 구성하는 항목 수를 파악하는 것은 리소스를 많이 소모하거나 심지어 불가능할 수도 있습니다.
로드 취소된 항목을 처리하는 데 어댑터 필요: 확장을 위해 목록을 준비하는 데 사용할 어댑터 또는 표시 메커니즘은 null 목록 항목을 처리해야 합니다. 예를 들어 데이터를 ViewHolder에 결합할 경우 로드 취소된 데이터를 보여주기 위한 기본값을 제공해야 합니다.
동일한 크기의 항목 뷰 필요: 소셜 네트워킹 업데이트와 같이 콘텐츠에 따라 목록 항목 크기가 변경될 수 있다면 항목 간 크로스 페이딩은 적합해 보이지 않습니다. 이런 상황에는 자리표시자를 사용하지 않는 것이 좋습니다.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-27(UTC)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-07-27(UTC)"],[],[],null,["# Display paged lists\n\nThis guide builds upon the [Paging Library\noverview](/topic/libraries/architecture/paging), describing how you can\npresent lists of information to users in your app's UI, particularly when this\ninformation changes.\n| **Caution:** This guide covers an older, deprecated version of the Paging library. For more information about the latest stable version of Paging, see the [Paging\n| 3 guides](/topic/libraries/architecture/paging/v3-overview).\n\nConnect your UI to your view model\n----------------------------------\n\nYou can connect an instance of\n[`LiveData\u003cPagedList\u003e`](/reference/androidx/lifecycle/LiveData) to a\n[`PagedListAdapter`](/reference/androidx/paging/PagedListAdapter), as shown\nin the following code snippet: \n\n### Kotlin\n\n```kotlin\nclass ConcertActivity : AppCompatActivity() {\n private val adapter = ConcertAdapter()\n\n // Use the 'by viewModels()' Kotlin property delegate\n // from the activity-ktx artifact\n private val viewModel: ConcertViewModel by viewModels()\n\n override fun onCreate(savedInstanceState: Bundle?) {\n super.onCreate(savedInstanceState);\n viewModel.concerts.observe(this, Observer { adapter.submitList(it) })\n }\n}\n```\n\n### Java\n\n```java\npublic class ConcertActivity extends AppCompatActivity {\n private ConcertAdapter adapter = new ConcertAdapter();\n private ConcertViewModel viewModel;\n\n @Override\n public void onCreate(@Nullable Bundle savedInstanceState) {\n super.onCreate(savedInstanceState);\n viewModel = new ViewModelProvider(this).get(ConcertViewModel.class);\n viewModel.concertList.observe(this, adapter::submitList);\n }\n}\n```\n\nAs data sources provide new instances of\n[`PagedList`](/reference/androidx/paging/PagedList), the activity sends\nthese objects to the adapter. The\n[`PagedListAdapter`](/reference/androidx/paging/PagedListAdapter)\nimplementation defines how updates are computed, and it automatically handles\npaging and list diffing. Therefore, your\n[`ViewHolder`](/reference/androidx/recyclerview/widget/RecyclerView.ViewHolder)\nonly needs to bind to a particular provided item: \n\n### Kotlin\n\n```kotlin\nclass ConcertAdapter() :\n PagedListAdapter\u003cConcert, ConcertViewHolder\u003e(DIFF_CALLBACK) {\n override fun onBindViewHolder(holder: ConcertViewHolder, position: Int) {\n val concert: Concert? = getItem(position)\n\n // Note that \"concert\" is a placeholder if it's null.\n holder.bindTo(concert)\n }\n\n companion object {\n private val DIFF_CALLBACK = ... // See #implement-diffing-callback section.\n }\n}\n```\n\n### Java\n\n```java\npublic class ConcertAdapter\n extends PagedListAdapter\u003cConcert, ConcertViewHolder\u003e {\n protected ConcertAdapter() {\n super(DIFF_CALLBACK);\n }\n\n @Override\n public void onBindViewHolder(@NonNull ConcertViewHolder holder,\n int position) {\n Concert concert = getItem(position);\n\n // Note that \"concert\" can be null if it's a placeholder.\n holder.bindTo(concert);\n }\n\n private static DiffUtil.ItemCallback\u003cConcert\u003e DIFF_CALLBACK\n = ... // See #implement-diffing-callback section.\n}\n```\n\nThe [`PagedListAdapter`](/reference/androidx/paging/PagedListAdapter)\nhandles page load events using a\n[`PagedList.Callback`](/reference/androidx/paging/PagedList.Callback)\nobject. As the user scrolls, the `PagedListAdapter` calls\n[`PagedList.loadAround()`](/reference/androidx/paging/PagedList#loadaround)\nto provide hints to the underlying\n[`PagedList`](/reference/androidx/paging/PagedList) as to\nwhich items it should fetch from the\n[`DataSource`](/reference/androidx/paging/DataSource).\n| **Note:** [`PagedList`](/reference/androidx/paging/PagedList) is content-immutable. This means that, although new content can be loaded into an instance of `PagedList`, the loaded items themselves cannot change once loaded. As such, if content in a `PagedList` updates, the [`PagedListAdapter`](/reference/androidx/paging/PagedListAdapter) object receives a completely new `PagedList` that contains the updated information.\n\nImplement the diffing callback\n------------------------------\n\nThe following sample shows a manual implementation of\n[`areContentsTheSame()`](/reference/androidx/recyclerview/widget/DiffUtil.ItemCallback#arecontentsthesame),\nwhich compares relevant object fields: \n\n### Kotlin\n\n```kotlin\nprivate val DIFF_CALLBACK = object : DiffUtil.ItemCallback\u003cConcert\u003e() {\n // The ID property identifies when items are the same.\n override fun areItemsTheSame(oldItem: Concert, newItem: Concert) =\n oldItem.id == newItem.id\n\n // If you use the \"==\" operator, make sure that the object implements\n // .equals(). Alternatively, write custom data comparison logic here.\n override fun areContentsTheSame(\n oldItem: Concert, newItem: Concert) = oldItem == newItem\n}\n```\n\n### Java\n\n```java\nprivate static DiffUtil.ItemCallback\u003cConcert\u003e DIFF_CALLBACK =\n new DiffUtil.ItemCallback\u003cConcert\u003e() {\n\n @Override\n public boolean areItemsTheSame(Concert oldItem, Concert newItem) {\n // The ID property identifies when items are the same.\n return oldItem.getId() == newItem.getId();\n }\n\n @Override\n public boolean areContentsTheSame(Concert oldItem, Concert newItem) {\n // Don't use the \"==\" operator here. Either implement and use .equals(),\n // or write custom data comparison logic here.\n return oldItem.equals(newItem);\n }\n};\n```\n\nBecause your adapter includes your definition of comparing items, the adapter\nautomatically detects changes to these items when a new `PagedList` object is\nloaded. As a result, the adapter triggers efficient item animations within your\n`RecyclerView` object.\n\nDiffing using a different adapter type\n--------------------------------------\n\nIf you choose not to inherit from\n[`PagedListAdapter`](/reference/androidx/paging/PagedListAdapter)---such as\nwhen you're using a library that provides its own adapter---you can still use the\nPaging Library adapter's diffing functionality by working directly with an\n[`AsyncPagedListDiffer`](/reference/androidx/paging/AsyncPagedListDiffer)\nobject.\n\nProvide placeholders in your UI\n-------------------------------\n\nIn cases where you want your UI to display a list before your app has finished\nfetching data, you can show placeholder list items to your users. The\n[`PagedList`](/reference/androidx/paging/PagedList) handles this case by\npresenting the list item data as `null` until the data is loaded.\n| **Note:** By default, the Paging Library enables this placeholder behavior.\n\nPlaceholders have the following benefits:\n\n- **Support for scrollbars:** The [`PagedList`](/reference/androidx/paging/PagedList) provides the number of list items to the [`PagedListAdapter`](/reference/androidx/paging/PagedListAdapter). This information allows the adapter to draw a scrollbar that conveys the full size of the list. As new pages load, the scrollbar doesn't jump because your list doesn't change size.\n- **No loading spinner necessary:** Because the list size is already known, there's no need to alert users that more items are loading. The placeholders themselves convey that information.\n\nBefore adding support for placeholders, though, keep the following\npreconditions in mind:\n\n- **Requires a countable data set:** Instances of [`DataSource`](/reference/androidx/paging/DataSource) from the [Room\n persistence library](/topic/libraries/architecture/room) can efficiently count their items. If you're using a custom local storage solution or a [network-only\n data architecture](/topic/libraries/architecture/paging#network-only-data-arch), however, it might be expensive or even impossible to determine how many items comprise your data set.\n- **Requires adapter to account for unloaded items:** The adapter or presentation mechanism that you use to prepare the list for inflation needs to handle null list items. For example, when binding data to a [`ViewHolder`](/reference/androidx/recyclerview/widget/RecyclerView.ViewHolder), you need to provide default values to represent unloaded data.\n- **Requires same-sized item views:** If list item sizes can change based on their content, such as social networking updates, crossfading between items doesn't look good. We strongly suggest disabling placeholders in this case.\n\nProvide feedback\n----------------\n\nShare your feedback and ideas with us through these resources:\n\n[Issue tracker](https://issuetracker.google.com/issues/new?component=413106&template=1096385) :bug:\n: Report issues so we can fix bugs.\n\nAdditional resources\n--------------------\n\nTo learn more about the Paging Library, consult the\nfollowing resources.\n\n### Samples\n\n- [Android Architecture Components Paging\n sample](https://github.com/android/architecture-components-samples/tree/paging2/PagingSample)\n- [Paging With Network Sample](https://github.com/android/architecture-components-samples/tree/paging2/PagingWithNetworkSample)\n\n### Codelabs\n\n- [Android Paging codelab](https://codelabs.developers.google.com/codelabs/android-paging/index.html?index=..%2F..%2Findex#0)\n\n### Videos\n\n- [Android Jetpack: manage infinite lists with RecyclerView and Paging\n (Google I/O '18)](https://www.youtube.com/watch?v=BE5bsyGGLf4)\n- [Android Jetpack: Paging](https://www.youtube.com/watch?v=QVMqCRs0BNA)\n\nRecommended for you\n-------------------\n\n- Note: link text is displayed when JavaScript is off\n- [Paging 2 library overview](/topic/libraries/architecture/paging)\n- [Migrate to Paging 3](/topic/libraries/architecture/paging/v3-migration)\n- [Gather paged data](/topic/libraries/architecture/paging/data)"]]