Is there an addHeaderView equivalent for RecyclerView?

后端 未结 19 1626
独厮守ぢ
独厮守ぢ 2020-11-21 23:35

I\'m looking for an equivalent to addHeaderView for a recycler view. Basically I want to have an image with 2 buttons be added as a header to the listview. Is there a differ

19条回答
  •  执念已碎
    2020-11-22 00:30

    If you want the header to be easily reused across multiple lists, take a look at the version 1.2.0 of recyclerview library. It introduces ConcatAdapter class which concatenates multiple adapters into a single one. So you can create a header adapter and easily combine it with any other adapter, like:

    myRecyclerView.adapter = ConcatAdapter(headerAdapter, listAdapter)
    

    The announcement article contains a sample how to display a loading progress in header and footer using ConcatAdapter.

    For the moment when I post this answer the version 1.2.0 of the library is in alpha stage, so the api might change. You can check the status here.

提交回复
热议问题