Last active
August 23, 2023 08:23
-
-
Save jeffdgr8/61a4c6432401bf2740cd17cd04f7ee4e to your computer and use it in GitHub Desktop.
SectionedRecyclerViewAdapter that implements StickyHeaderHandler for using https://github.com/bgogetap/StickyHeaders with https://github.com/luizgrp/SectionedRecyclerViewAdapter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.brandongogetap.stickyheaders.exposed.StickyHeader | |
import com.brandongogetap.stickyheaders.exposed.StickyHeaderHandler | |
import io.github.luizgrp.sectionedrecyclerviewadapter.SectionedRecyclerViewAdapter | |
/** | |
* [SectionedRecyclerViewAdapter] that implements [StickyHeaderHandler]. | |
*/ | |
class StickyHeaderSectionedRecyclerViewAdapter: SectionedRecyclerViewAdapter(), StickyHeaderHandler { | |
override fun getAdapterData(): List<*> { | |
val data = ArrayList<StickyHeader?>() | |
copyOfSectionsMap.values.forEach { section -> | |
if (section.hasHeader()) { | |
data.add(StickyHeaderImpl()) | |
} | |
repeat(section.contentItemsTotal) { data.add(null) } | |
} | |
return data | |
} | |
class StickyHeaderImpl: StickyHeader | |
} |
Thank you a lot, 4 years already but still helpful
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@cedb777 that all looks correct. How are you setting up your RecyclerView? Besides assigning the
StickyHeaderSectionedRecyclerViewAdapter
to the adapter, be sure to set the layout manager toStickyLayoutManager
, which takes the adapter as a constructor argument. See docs.