Skip to content

Latest commit

 

History

History
52 lines (38 loc) · 2.07 KB

single_data_adapter.md

File metadata and controls

52 lines (38 loc) · 2.07 KB

AssemblySingleData*Adapter

在使用 Concat*Adapter 实现 header 或 footer 时,有时候需要一个只有一条数据的 Adapter 来作为 header 或 footer,这时候 AssemblySingleData*Adapter 就派上用场了,如下:

val appsOverviewAdapter =
    AssemblySingleDataRecyclerAdapter(AppsOverviewItemFactory(requireActivity()))
val recyclerAdapter = AssemblyRecyclerAdapter<Any>(
    listOf(
        AppItemFactory(requireActivity()),
        ListSeparatorItemFactory(requireActivity())
    )
)
val footerLoadStateAdapter =
    AssemblySingleDataRecyclerAdapter(LoadStateItemFactory(requireActivity()))

binding.recyclerRecycler.apply {
    adapter = ConcatAdapter(appsOverviewAdapter, recyclerAdapter, footerLoadStateAdapter)
}

// 数据加载成功后更新数据
appsOverviewAdapter.data = AppsOverview()
footerLoadStateAdapter.data = LoadState.NotLoading(true)

更多示例