重点 (Top highlight)
ConcatAdapter
is a new class available in recyclerview:1.2.0-alpha02
which enables you to sequentially combine multiple adapters
to be displayed in a single RecyclerView
. This enables you to better encapsulate your adapters rather than having to combine many data sources into a single adapter, keeping them focused and re-usable.
ConcatAdapter
是recyclerview:1.2.0-alpha02
可用的新类,它使您可以顺序组合多个adapters
,以在单个RecyclerView
显示。 这使您可以更好地封装适配器,而不必将许多数据源组合到单个适配器中,从而使它们集中并可重复使用。
One use case for this is displaying a list loading state in a header or footer: when the list is retrieving data from the network, we want to show a progress spinner; in case of error, we want to show the error and a retry button.
一个用例是在页眉或页脚中显示列表加载状态:当列表从网络中检索数据时,我们想显示一个进度条。 如果出现错误,我们要显示错误和重试按钮。
![Image for post](https://img-blog.csdnimg.cn/img_convert/e32c820bd270e5af7a5d53a0bdd95f44.png)
介绍Concat Adapter
(Introducing ConcatAdapter
)
ConcatAdapter
allows us to display the contents of multiple adapters, in a sequence. For example, let’s say that we have the following 3 adapters:
ConcatAdapter
允许我们按顺序显示多个适配器的内容。 例如,假设我们有以下3个适配器:
val firstAdapter: FirstAdapter = …
val secondAdapter: SecondAdapter = …
val thirdAdapter: ThirdAdapter = …val concatAdapter = ConcatAdapter(firstAdapter, secondAdapter,
thirdAdapter)recyclerView.adapter = concatAdapter
The recyclerView
will display the items from each adapter sequentially.
recyclerView
将顺序显示每个适配器中的项目。
Having different adapters allows you to better separate the concerns of each sequential part of a list. For example, if you want to display a header, you don’t need to put the logic related to the header display in the same adapter that handles the list display, rather you can encapsulate it in its own adapter.
使用不同的适配器可以使您更好地分离列表的每个顺序部分。 例如,如果要显示标题,则不需要将与标题显示相关的逻辑放在处理列表显示的同一适配器中,而是可以将其封装在其自己的适配器中。
![Image for post](https://img-blog.csdnimg.cn/img_convert/cbc889b65bdc17e9e7578607c3dc853c.png)