Ankit Kumar
1 min readJul 16, 2021

--

Recycler View With Sticky Headers & Multiple Layout (Kotlin , View Binding)

Here we will look on how to inflate multiple views in a recycler view and put a sticky header
For complete code : GitHub

Adapter code for recycler view

Activity Code where recycler view is initialised
In OnScrollChanged method inside RvStickyScroll code for header is written

Whenever on top of our recycler view if any header layout is completely visible then we hide header textView of activity ,
but if header layout if partially visible or there is no header layout on top then we show header textview of activity and set text to header value

Model class will be like open class RvStickyModel {
open val header: String? = null
}
class HeaderModel(hdr: String) : RvStickyModel() {
override var header = hdr
}
class ContentModel(desc: String,hdr: String) : RvStickyModel() {
val description = desc
override val header = hdr
}

You can also send a any type list to adapter and inflate any number of layouts

Thanks, Hope it helps you!

--

--