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.
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
addHeaderViewmethod thatRecyclerViewintentionally does not provide. - Putting header offset logic everywhere in one adapter when
ConcatAdapterwould 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
- '
RecyclerViewhas no directaddHeaderViewequivalent.' - 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.
Related reading
- Is there an easy way to add a border to the top and bottom of an Android View?
- Is there any callback mechanism in android when there is data available to read in socket
- Is there any limit in storing values in NSUserDefaults?
- Is there any way to check if iOS app is in background?
- Is there any way to debug chrome in any IOS device
- is there any way to distribute ios applications outside app store?
- Is there any way to hide - Delete button while editing UITableView
- Is there any way to see the file system on the iOS simulator?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseNo 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 courseData 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.