explaingit

timehop/sticky-headers-recyclerview

3,786JavaAudience · developerComplexity · 2/5Setup · easy

TLDR

An Android library that makes section headers in a RecyclerView stick to the top of the screen as you scroll, so users always see which category they're in, like contacts grouped by letter or items grouped by date.

Mindmap

mindmap
  root((Sticky Headers RV))
    What it does
      Sticky section headers
      Scroll-aware pinning
      RecyclerView decorator
    How it works
      Canvas drawing
      Decorator pattern
      No view hierarchy
    Integration
      Adapter interface
      Three methods needed
      Header click handler
    Limitations
      No touch highlight states
      No async image loading
      Unmaintained since 2015
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Add alphabetical sticky headers to a contacts list in an Android app so the current letter stays visible while scrolling.

USE CASE 2

Display a categorized product list with date or category headers that stay pinned at the top as users scroll through.

USE CASE 3

Build a chat log view with sticky date separators that stay visible as the user scrolls through message history.

USE CASE 4

Handle taps on stuck section headers to trigger collapse or expand behavior for that section.

Tech stack

JavaAndroidRecyclerView

Getting it running

Difficulty · easy Time to first run · 30min

Headers are drawn directly on canvas, not in the view hierarchy, async image loading in headers will cause rendering problems.

In plain English

sticky-headers-recyclerview is an Android library that adds section headers to scrollable lists built with RecyclerView. When a user scrolls through a categorized list such as contacts grouped alphabetically or items grouped by date, the current section header sticks at the top of the screen until the next section arrives and replaces it. The library works as a decorator, meaning you add it to an existing RecyclerView without restructuring your existing code. Setup involves three classes. The adapter interface adds three methods to whatever adapter you already have: one to return a header ID for each list item, and two to create and populate the header view. The decoration class handles the actual rendering and requires no extra configuration beyond being attached to the RecyclerView. A third class handles click events on the stuck header. One thing to be aware of: the header views are drawn directly onto the canvas rather than being added to the view hierarchy. This means touch states such as highlight on press do not work on them, and loading images into header views asynchronously may cause problems. Header views are also not recycled, which the project acknowledges as a known limitation. Item animators may not interact cleanly with the decoration. The library supports both vertical and horizontal scrolling lists and requires Android API level 11 or above. When your data changes, you must manually call invalidateHeaders on the decoration to keep the headers in sync, since the decoration is not aware of the adapter directly. The repository is marked as unmaintained. The last release, version 0.4.3, was published in December 2015. The project credited Emil Sjolander's StickyListHeaders as inspiration for the original concept.

Copy-paste prompts

Prompt 1
I have a RecyclerView showing contacts grouped alphabetically. Show me how to use sticky-headers-recyclerview to add letter headers that stick at the top as I scroll.
Prompt 2
How do I implement the StickyRecyclerHeadersAdapter interface for my existing adapter to return a stable header ID for each item position?
Prompt 3
My sticky-headers-recyclerview headers are not updating when my dataset changes. How do I call invalidateHeaders correctly and where should I put that call?
Prompt 4
I want click events on the stuck header in sticky-headers-recyclerview. How do I set up the click handler and get the section position of the tapped header?
Open on GitHub → Explain another repo

← timehop on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.