0Pricing
Jetpack Compose Academy · Leçon

En-têtes persistants et listes par sections

Regroupez les éléments avec des en-têtes épinglés.

En-têtes persistants et listes par sections est une leçon Jetpack Compose Academy gratuite sur CoddyKit. Ceci est la leçon 4 sur 4. Tu peux lire la leçon complète ci-dessous gratuitement — puis la pratiquer en direct dans le navigateur avec un éditeur de code intégré et un tuteur IA 24/7. Elle fait partie du parcours d'apprentissage Jetpack Compose Academy, et ta progression se synchronise sur le web et l'application CoddyKit. Le cours Jetpack Compose Academy comprend 4 leçons au total.

Certaines parties de cette leçon n'ont pas encore été traduites et s'affichent en anglais.

Lists Often Have Sections

Real lists group data, like contacts by letter or emails by date. Each group deserves a clear header above its rows.

A Header Is Just an item

The simplest header is a single item block holding a styled Text. Place it before the group's items and it scrolls along.

item { Text("A", style = MaterialTheme.typography.titleMedium) }

Build Sections in a Loop

Loop over your grouped data and, for each group, add its header item then its items. This builds a clean section list.

groups.forEach { (letter, names) ->
    item { Text(letter) }
    items(names) { Text(it) }
}

The Problem: Headers Scroll Away

A plain header scrolls off the top with its rows. Mid-section, you lose track of which group you're even looking at.

Enter Sticky Headers

A stickyHeader pins itself to the top while its section scrolls beneath it. The current group label always stays in view. 📌

stickyHeader { Text("A") }

Use It Like item

Call stickyHeader exactly where you'd put a header item, just before the section's items block. Compose handles the pinning.

groups.forEach { (letter, names) ->
    stickyHeader { Text(letter) }
    items(names) { Text(it) }
}

One Header at a Time

As a new section reaches the top, its header pushes the old one up and out. Only the current group's header stays pinned.

Headers Need a Background

Give the sticky header a solid background. Without one, scrolling rows show through and the pinned text becomes hard to read.

stickyHeader {
    Text(letter, Modifier.background(Color.White).fillMaxWidth())
}

Group Your Data First

Prepare a grouped structure before composing, often with groupBy. Clean data makes the section loop short and readable.

val byLetter = names.groupBy { it.first() }

Sticky Headers Lives in LazyColumn

The stickyHeader builder is part of the LazyColumn scope. It works only inside a lazy list, not a plain Column.

Polished, Scannable Lists

Together, section headers and sticky pinning turn a long flat list into a scannable, professional screen users can navigate fast.

Quick Check

What does a sticky header do?

Recap: Headers That Stick

Build sections by pairing a header with items, then swap to stickyHeader so the group label pins while you scroll. Add a background! 🎉

Questions Fréquemment Posées

La leçon « En-têtes persistants et listes par sections » est-elle gratuite ?

Oui — le texte complet de « En-têtes persistants et listes par sections » est gratuit à lire ici sur le web. Pour la pratiquer de manière interactive (un éditeur de code intégré et un tuteur IA 24/7) et déverrouiller le reste du cours Jetpack Compose Academy, passe à CoddyKit PRO. Le cours Jetpack Compose Academy comprend 4 leçons au total.

Qu'est-ce que j'apprendrai dans « En-têtes persistants et listes par sections » ?

Regroupez les éléments avec des en-têtes épinglés. Tu pratiques Jetpack Compose Academy avec du code pratique que tu exécutes directement dans le navigateur, et un tuteur IA 24/7 répond à tes questions au fur et à mesure que tu avances dans la leçon.

Dois-je avoir de l'expérience pour commencer Jetpack Compose Academy ?

Aucune expérience préalable n'est requise. Jetpack Compose Academy sur CoddyKit est structuré pour les débutants jusqu'aux apprenants avancés, donc tu peux commencer ici ou depuis le début et avancer à ton rythme. Ceci est la leçon 4 sur 4.

Combien de temps prend la leçon « En-têtes persistants et listes par sections » ?

La plupart des leçons CoddyKit prennent environ 5–10 minutes. Chacune est courte et interactive, tu progresses régulièrement et tu repiques exactement où tu t'es arrêté sur le web et l'app.

Peux-tu écrire et exécuter du code dans cette leçon Jetpack Compose Academy ?

Oui. Chaque leçon Jetpack Compose Academy inclut un éditeur de code intégré, tu écris et exécutes du vrai code directement dans ton navigateur et tu reçois des retours IA instantanés — aucune configuration locale requise.

Toutes les leçons de ce cours

  1. LazyColumn ou colonne déroulable
  2. items et itemsIndexed
  3. Clés pour des listes stables et rapides
  4. En-têtes persistants et listes par sections
← Retour à Jetpack Compose Academy