#mutable的列表
- Compose中,针对列表进行动态化刷新,可以使用如下方式:
List
val list by mutableStateListOf(1,2,3,4)
setContent{
Column{
Button("Add",Modifier.clickable{
list.add(list.last() + 1)
})//一旦点击Add,
for(i in list){
Text("value is $i")
}
}
}
Map
val map by mutableStateMapOf(1 to "One",2 to "Two",3 to "Three",4 to "Four")
setContent{
Column{
Button("Add",Modifier.clickable{
map[5] = "Five"
})//一旦点击Add,
for((key,value) in map){
Text("key is $key , value is $value")
}
}
}