0Pricing
Jetpack Compose Academy · レッスン

itemsとitemsIndexed

データの行のコレクションを描画します。

「itemsとitemsIndexed」はCoddyKit上の無料Jetpack Compose Academyレッスンです。 これはレッスン2/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはJetpack Compose Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Jetpack Compose Academyコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

From Data to Rows

Your data usually lives in a list, like a List of strings or objects. The items block turns each element into a row on screen.

The items Function

Call items with your collection and a lambda. Compose runs the lambda for each element it needs to show.

LazyColumn {
    items(fruits) { fruit ->
        Text(fruit)
    }
}

The Element Parameter

The lambda receives one element at a time. Name it clearly, like fruit or user, then build UI from that single value.

items(users) { user ->
    Text(user.name)
}

Build a Whole Row

The lambda can hold any layout, not just Text. Wrap several composables in a Row to make a richer list item.

items(users) { user ->
    Row { Text(user.name); Text(user.age.toString()) }
}

When You Need the Position

Sometimes you want the row's index, like showing a rank number or alternating colors. Plain items doesn't give you that.

Meet itemsIndexed

Use itemsIndexed when you need the position. Its lambda receives both the index and the element together.

itemsIndexed(songs) { index, song ->
    Text("$index: $song")
}

Index Comes First

Order matters: in itemsIndexed the index is the first parameter and the element is the second. Swapping them is a common slip.

itemsIndexed(tasks) { i, task ->
    Text("Step ${i + 1}: $task")
}

Numbering Made Easy

Index starts at zero, so add one for human-friendly numbering. This makes ranked or step-by-step lists feel natural.

Add a Single Fixed Row

Need one standalone row, like a header or footer? Use item (singular) for a single piece of content among your items blocks.

LazyColumn {
    item { Text("My List") }
    items(data) { Text(it) }
}

Mix and Match Freely

Inside one LazyColumn you can combine several item and items calls. They render in the order you declare them.

Pick the Right Tool

Reach for items when the element is enough, and itemsIndexed when you also need each row's position. That's the whole choice.

Quick Check

Pick the right builder for the job.

Recap: items and itemsIndexed

Use items to map data to rows, itemsIndexed when you need the position, and item for a single fixed row. Mix them freely. 🎯

よくある質問

「itemsとitemsIndexed」レッスンは無料ですか?

はい。「itemsとitemsIndexed」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Jetpack Compose Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Jetpack Compose Academyコースには全4レッスンが含まれています。

「itemsとitemsIndexed」で何を学びますか?

データの行のコレクションを描画します。 ブラウザで直接実行するハンズオンコードでJetpack Compose Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Jetpack Compose Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのJetpack Compose Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン2/4です。

「itemsとitemsIndexed」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このJetpack Compose Academyレッスンでコードを書いて実行できますか?

はい。すべてのJetpack Compose Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. LazyColumnとスクロール可能なColumn
  2. itemsとitemsIndexed
  3. 安定して高速なリストのキー
  4. 固定ヘッダーとセクションリスト
← Jetpack Compose Academyに戻る