Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)
        }
    }
}
like image 750
Bubbly Avatar asked Nov 19 '25 04:11

Bubbly


1 Answers

If you just want 3 items, then replace

items = messages

with

items = messages.take(3)
like image 138
Francesc Avatar answered Nov 20 '25 17:11

Francesc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!