addHeaderView in RecyclerView

As we all know there is addHeaderView in ListView to add header item. But there is no equivalent to this in RecyclerView. Here i am sharing short demo for addHeaderView in RecyclerView.

add dependency in build.gradle

add RecyclerView in your main xml

row_layout.xml

header.xml

Here is the code for your adapter class

ItemDecoration.java for adding divider in RecyclerView

line_divider.xml for custom divider of RecyclerView

Finally initialize RecyclerView in your MainActivity and set adapter for it.

addHeaderView in RecyclerView

 

 

Follow me

Ravi Rupareliya

He is author of Android Gig. He loves to explore new technologies and have worked on Android, React Native, Action on Google and Flutter.
Ravi Rupareliya
Follow me

Latest posts by Ravi Rupareliya (see all)

Requesting Runtime Permission – Part 2
Runtime Permission in Pre-Marshmallow