Jetpack Compose LazyColumn List Example

Short answer: to build a scrolling list in Jetpack Compose, put your items in a LazyColumn and call items() with your list. Each item is a composable, such as a Card, and LazyColumn only renders the rows that are on screen.

In this tutorial you will build a small fruit list app with a data class, a card for each row, a reusable list composable and click handling. If you only need a simple scrolling screen, read our guide to the scrollable Column in Jetpack Compose first. The code uses Material 3 and Kotlin.

What you will build

A screen that shows a list of fruits. Each row is a card with an emoji, a name and a short description. Tapping a card shows which fruit is selected.

Step 1: Create the project

In Android Studio, create a new project with the Empty Activity template, which sets up Jetpack Compose and Material 3 for you. Keep the default MainActivity.

Step 2: Create the data

Create a file named Fruit.kt with a data class and some sample data:

data class Fruit(
    val id: Int,
    val name: String,
    val description: String,
    val emoji: String
)

val sampleFruits = listOf(
    Fruit(1, "Apple", "Crisp and sweet, great for snacks and pies.", "๐ŸŽ"),
    Fruit(2, "Banana", "Soft and energy-rich, a classic on-the-go fruit.", "๐ŸŒ"),
    Fruit(3, "Orange", "Juicy and full of vitamin C.", "๐ŸŠ"),
    Fruit(4, "Grapes", "Small, sweet and perfect for sharing.", "๐Ÿ‡"),
    Fruit(5, "Strawberry", "Bright, tangy and loved in desserts.", "๐Ÿ“"),
    Fruit(6, "Watermelon", "Refreshing and over 90% water.", "๐Ÿ‰")
)

Give every item a unique id. You will use it as the list key in Step 4.

Step 3: Build the row (FruitCard)

Create FruitCard.kt. This composable draws one row:

@Composable
fun FruitCard(
    fruit: Fruit,
    onClick: () -> Unit,
    modifier: Modifier = Modifier
) {
    Card(
        onClick = onClick,
        modifier = modifier.fillMaxWidth(),
        elevation = CardDefaults.cardElevation(defaultElevation = 2.dp)
    ) {
        Row(
            modifier = Modifier.padding(16.dp),
            verticalAlignment = Alignment.CenterVertically
        ) {
            Text(text = fruit.emoji, fontSize = 32.sp)
            Spacer(modifier = Modifier.width(16.dp))
            Column {
                Text(
                    text = fruit.name,
                    style = MaterialTheme.typography.titleMedium
                )
                Text(
                    text = fruit.description,
                    style = MaterialTheme.typography.bodyMedium
                )
            }
        }
    }
}

Card(onClick = ...) is stable in recent Material 3 versions. If your project uses an older version, add @OptIn(ExperimentalMaterial3Api::class) to the function.

Step 4: Build the list with LazyColumn

Create FruitList.kt:

@Composable
fun FruitList(
    fruits: List<Fruit>,
    onFruitClick: (Fruit) -> Unit,
    modifier: Modifier = Modifier
) {
    LazyColumn(
        modifier = modifier,
        contentPadding = PaddingValues(16.dp),
        verticalArrangement = Arrangement.spacedBy(12.dp)
    ) {
        items(items = fruits, key = { it.id }) { fruit ->
            FruitCard(
                fruit = fruit,
                onClick = { onFruitClick(fruit) }
            )
        }
    }
}
  • contentPadding adds space around the whole list without clipping items while scrolling.
  • verticalArrangement adds even spacing between rows.
  • key = { it.id } lets Compose track each item correctly when the list changes, which keeps scroll position and item state stable.
  • Import androidx.compose.foundation.lazy.items for the items function.

Step 5: Show the list in MainActivity

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            MaterialTheme {
                Surface(modifier = Modifier.fillMaxSize()) {
                    var selected by remember { mutableStateOf<Fruit?>(null) }

                    Column {
                        selected?.let {
                            Text(
                                text = "Selected: ${it.name}",
                                modifier = Modifier.padding(16.dp),
                                style = MaterialTheme.typography.titleLarge
                            )
                        }
                        FruitList(
                            fruits = sampleFruits,
                            onFruitClick = { selected = it },
                            modifier = Modifier.weight(1f)
                        )
                    }
                }
            }
        }
    }
}

Run the app. You should see six cards, and tapping one shows its name at the top. Add import androidx.compose.runtime.getValue and import androidx.compose.runtime.setValue if Android Studio reports an error on by remember.

Common mistakes with LazyColumn lists

  • Nesting a LazyColumn inside a vertically scrolling Column. This crashes because the inner list receives infinite height. Use one scrolling container.
  • Skipping the key. Without a stable key, items can lose state or animate wrongly when you insert or remove rows.
  • Doing heavy work inside the item lambda. Keep item composables light and move calculations into a ViewModel or remember.
  • Using a plain mutable list. Compose will not notice changes. Use mutableStateListOf or expose a List from a StateFlow in a ViewModel.

FAQ

What is LazyColumn in Jetpack Compose?

LazyColumn is a vertically scrolling list that only composes and lays out the items currently visible, similar to RecyclerView in the View system but with much less code.

How do I handle item clicks in a LazyColumn?

Pass a click callback into each item composable, as FruitCard does with onClick, and handle it in the parent or a ViewModel.

What is the difference between LazyColumn and RecyclerView?

LazyColumn needs no adapter or ViewHolder. You describe each item with a composable, and Compose handles recycling and updates.

How do I add headers or different item types?

Use item { } for a single header and items(...) for the rows in the same LazyColumn. Use stickyHeader { } for headers that stay pinned.

Keep going with more Jetpack Compose tutorials.