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

 

 

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

  • how to switch layout in each list..? like this
    convertView = LayoutInflater.from(context).inflate(R.layout.diff_video, viewGroup, false);

    • you can take a look at onCreateViewHolder(), there i have just taken 2 layout reference, one for header and one for normal views, you can take as many as you want according to the needs.