Bubbly
Bubbly

Reputation: 43

How to limit items count in LazyColumn?

I wanted to limit the items to 3 in LazyColumn in the below code,

@Composable
fun MessageList(messages: List<Message>) {
    LazyColumn {
        items(
            items = messages,
            key = { message ->
                // Return a stable + unique key for the item
                message.id
            }
        ) { message ->
            MessageRow(message)
        }
    }
}

Upvotes: 3

Views: 2461

Answers (1)

Francesc
Francesc

Reputation: 29320

If you just want 3 items, then replace

items = messages

with

items = messages.take(3)

Upvotes: 7

Related Questions