Skip to content

Android Compose Add a Scrollable List #240

@mikeborn206-dot

Description

@mikeborn206-dot

[Name of the Codelab or Codelab URL]
(https://developer.android.com/codelabs/basic-android-kotlin-compose-training-add-scrollable-list?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-compose-unit-3-pathway-2%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-compose-training-add-scrollable-list#0)

Describe the problem
Several problems here;
1)The code sample provided would not build after downloading and opening the folder. (Studio version info below)

In which lesson and step of the codelab can this issue be found?
Lesson number + step number.

Lesson 2 (scrollable list) step 3.

  1. On the final page with the coding instructions (before the final code page), there are several mistakes.

For the AffirmationsList function, codelab presented:

@composable
fun AffirmationList(affirmationList: List, modifier: Modifier = Modifier) {
LazyColumn(modifier = modifier) {
items(affirmationList) { affirmation ->
AffirmationCard(
affirmation = affirmation,
modifier = Modifier.padding(8.dp)
)
}
}
}

I had to re-write the code as follows (adding an index var to keep track of List index in the Lambda for the items() call:

My code:

@composable
fun AffirmationsList(affirmationList: List, modifier: Modifier = Modifier) {

**var listIndex = 0**

LazyColumn(modifier = modifier) {
    items(affirmationList.**size**) {affirmation ->

        AffirmationCard(
            affirmation = affirmationList**[listIndex],**
            modifier = Modifier.padding(8.dp))

        **if(listIndex < affirmationList.size) ++listIndex**
    }
}

}

How to reproduce?
What are the exact steps to reproduce the problem?
Would not build because the the argument to the items() call for the LazyColumn composable is an Int not a List.
An index(iterator) is needed to keep track of the current affirmation index on the callbacks in the items() Lambda code

Versions

  1. What version of Android Studio are you using? Studio Info follows:
  2. What API level are you targeting? Medium Phone API 36.1

Android Studio Panda 2 | 2025.3.2
Build #AI-253.30387.90.2532.14935130, built on February 25, 2026
Runtime version: 21.0.9+-14787801-b1163.94 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Toolkit: sun.awt.windows.WToolkit
Windows 10.0
StudioFlags with current overrides:
LazyStudioFlagSettings(StudioFlagSettings(data.size=0)):
PropertyOverrides(cache.size=477):
flags.configuration.level=COMPLETE
MendelOverrides(MendelFlagsProvider count=1):
ServerFlagOverrides(Name: analytics/surveys/followup
PercentEnabled: 100
Value: custom proto

    Name: analytics/surveys/sentiment/url
    PercentEnabled: 100
    Value: https://google.qualtrics.com/jfe/form/SV_4ZzP5RfbOtMwbxc
    
    Name: cxx/page_align_16kb
    PercentEnabled: 100
    Value: custom proto
    
    Name: exceptions/ClassCastException
    PercentEnabled: 100
    Value: custom proto
    
    Name: exceptions/ClassNotFoundException
    PercentEnabled: 100
    Value: custom proto
    
    Name: exceptions/PluginException-0073ff27
    PercentEnabled: 100
    Value: custom proto
    
    Name: exceptions/PluginException-722647e2
    PercentEnabled: 100
    Value: custom proto
    
    Name: exceptions/PluginException-8b332315
    PercentEnabled: 100
    Value: custom proto
    
    Name: exceptions/b_372743206
    PercentEnabled: 100
    Value: custom proto
    
    Name: exceptions/b_452882570
    PercentEnabled: 100
    Value: custom proto
    
    Name: exceptions/b_458923805
    PercentEnabled: 100
    Value: custom proto
    
    Name: studio_flags/benchmark.survey.2026.enable
    PercentEnabled: 100
    Value: true
    
    Name: studio_flags/cloud.enabled
    PercentEnabled: 100
    Value: true
    
    Name: studio_flags/firebasetestlab.direct.access.monthly.quota
    PercentEnabled: 100
    Value: true
    
    Name: studio_flags/rundebug.install.use.pm.terminate
    PercentEnabled: 100
    Value: false
    
    Name: studio_flags/studiobot.askgemini.include.build.files.in.context
    PercentEnabled: 100
    Value: true
    
    Name: studio_flags/studiobot.chat.use.compose.for.ui
    PercentEnabled: 100
    Value: true
    
    Name: studio_flags/studiobot.compiler.error.context.enabled
    PercentEnabled: 100
    Value: true
    
    Name: studio_flags/studiobot.completions.per.hour
    PercentEnabled: 100
    Value: 36000
    
    Name: studio_flags/studiobot.conversations.per.hour
    PercentEnabled: 100
    Value: 500
    
    Name: studio_flags/studiobot.current.file.context
    PercentEnabled: 100
    Value: true
    
    Name: studio_flags/studiobot.dac.skills.limit
    PercentEnabled: 100
    Value: 0
    
    Name: studio_flags/studiobot.generations.per.hour
    PercentEnabled: 100
    Value: 3600
    
    Name: studio_flags/studiobot.inline.code.completion.file.context.enabled
    PercentEnabled: 100
    Value: true
    
    Name: studio_flags/studiobot.npa.icon.image.generation.model.name
    PercentEnabled: 100
    Value: gemini-2.5-flash-image
    
    Name: studio_flags/studiobot.npa.mockup.image.generation.model.name
    PercentEnabled: 100
    Value: gemini-3-pro-image-preview
    
    Name: studio_flags/studiobot.project.facts.context.enabled
    PercentEnabled: 100
    Value: true
    
    Name: studio_flags/studiobot_gias_user_tier
    PercentEnabled: 100
    Value: custom proto
    
    Name: studio_flags/studiobot_push_notifications/notification_flag_list
    PercentEnabled: 100
    Value: custom proto
    
    ):
rundebug.install.use.pm.terminate=false
studiobot.askgemini.include.build.files.in.context=true
studiobot.compiler.error.context.enabled=true
studiobot.completions.per.hour=36000
studiobot.conversations.per.hour=500
studiobot.current.file.context=true
studiobot.generations.per.hour=3600
studiobot.inline.code.completion.file.context.enabled=true
studiobot.project.facts.context.enabled=true

AgpReleaseBranchProvider(releasedWithAgp=true):
gradle.ide.use.alongside.agp=true
AgpTestSuitesProvider(journeysWithGeminiEnabled=false):
GC: G1 Young Generation, G1 Concurrent GC, G1 Old Generation
Memory: 2048M
Cores: 8
Registry:
ide.experimental.ui=true

Additional information
Add any other context about the problem here.

codelab: basic-android-compose-training-add-scrollable-list

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions