RecyclerView
Android development
header view
Android UI
RecyclerView customization

Is there an addHeaderView equivalent for RecyclerView?

Codemia Knowledge Hub ·

Introduction

RecyclerView does not include a direct addHeaderView method like ListView. That is intentional: RecyclerView is lower-level and expects headers, footers, and content sections to be modeled through adapters rather than special built-in view slots.

The modern answer is adapter composition

There are two common ways to add a header. The older pattern is a single adapter with multiple view types. The cleaner modern pattern is ConcatAdapter, which lets you keep the header and the main list in separate adapters and combine them.

For many projects, ConcatAdapter is the simplest answer because it avoids position offset math inside one giant adapter.

kotlin
1class HeaderAdapter(private val title: String) :
2    RecyclerView.Adapter<HeaderAdapter.HeaderViewHolder>() {
3
4    class HeaderViewHolder(view: View) : RecyclerView.ViewHolder(view) {
5        val titleView: TextView = view.findViewById(R.id.headerTitle)
6    }
7
8    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HeaderViewHolder {
9        val view = LayoutInflater.from(parent.context)
10            .inflate(R.layout.list_header, parent, false)
11        return HeaderViewHolder(view)
12    }
13
14    override fun onBindViewHolder(holder: HeaderViewHolder, position: Int) {
15        holder.titleView.text = title
16    }
17
18    override fun getItemCount(): Int = 1
19}
20
21class UserAdapter(private val users: List<String>) :
22    RecyclerView.Adapter<UserAdapter.UserViewHolder>() {
23
24    class UserViewHolder(view: View) : RecyclerView.ViewHolder(view) {
25        val nameView: TextView = view.findViewById(R.id.userName)
26    }
27
28    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): UserViewHolder {
29        val view = LayoutInflater.from(parent.context)
30            .inflate(R.layout.list_item_user, parent, false)
31        return UserViewHolder(view)
32    }
33
34    override fun onBindViewHolder(holder: UserViewHolder, position: Int) {
35        holder.nameView.text = users[position]
36    }
37
38    override fun getItemCount(): Int = users.size
39}
40
41val recyclerView = findViewById<RecyclerView>(R.id.recyclerView)
42recyclerView.layoutManager = LinearLayoutManager(this)
43recyclerView.adapter = ConcatAdapter(
44    HeaderAdapter("Team Members"),
45    UserAdapter(listOf("Ada", "Grace", "Linus"))
46)

This keeps responsibilities clear. The header adapter owns the header view. The item adapter owns the list items. The RecyclerView sees one combined stream of rows.

When a single adapter still makes sense

If you need tight control over all positions, a single adapter with different view types is still valid. In that design, position 0 might be the header and the real data starts at position 1. The tradeoff is that every item count, bind call, and click listener must account for the offset.

That approach becomes especially annoying when you later add a footer, loading row, or empty state. What started as one extra row turns into several manual branches.

Grid and staggered layouts need extra care

In a GridLayoutManager, a header often needs to span all columns. That requires a custom SpanSizeLookup so the header consumes the full width while normal items keep the regular span count.

This is one reason adapter composition is attractive. It keeps header identity explicit, which makes layout rules easier to reason about.

Think of the header as data, not a special case

The biggest mental shift from ListView is to stop looking for a magic header API. In RecyclerView, the header is simply another row type or another adapter section. Once you adopt that model, headers, banners, empty states, and loading indicators all fit into the same architecture.

If you are already using paging or multiple sections, the same idea scales naturally. A header is just one more part of the list contract.

Common Pitfalls

  • Searching for a built-in addHeaderView method that RecyclerView intentionally does not provide.
  • Putting header offset logic everywhere in one adapter when ConcatAdapter would keep the code simpler.
  • Forgetting full-span handling for headers in a grid layout.
  • Treating click positions as raw data indices after adding a header row.
  • Hard-coding header behavior in a way that makes empty states or footers harder to add later.

Summary

  • 'RecyclerView has no direct addHeaderView equivalent.'
  • The cleanest modern solution is usually ConcatAdapter.
  • A single adapter with multiple view types also works, but it introduces manual position offsets.
  • Grid layouts often need special span handling so the header covers all columns.
  • Model the header as part of the adapter structure rather than expecting a special framework API.

Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Basis Lab
No course covers this one yet

Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.

Build my course
Data Structures & Algorithms practice on Codemia

Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.

Practice algorithms