@Composable
fun ListDemo() {
val items = remember { mutableStateListOf("Item 1", "Item 2", "Item 3") }
Column {
LazyColumn {
items(items) { item ->
Text(
text = item,
modifier = Modifier
.fillMaxWidth()
.padding(8.dp)
)
}
}
// Button to add an item
Button(onClick = {
items.add("Item ${items.size + 1}")
}) {
Text("Add Item")
}
// Button to remove an item
Button(onClick = {
if (items.isNotEmpty()) {
items.removeAt(items.size - 1)
}
}) {
Text("Remove Last Item")
}
}
}
01-27
4427
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)