【发布时间】:2020-06-30 14:15:43
【问题描述】:
当制作一个 xml 无限列表时需要创建RecyclerView 并添加RecyclerViewOnScrollListener。如何在 Jetpack Compose 中进行操作?
【问题讨论】:
标签: android kotlin android-recyclerview android-jetpack-compose
当制作一个 xml 无限列表时需要创建RecyclerView 并添加RecyclerViewOnScrollListener。如何在 Jetpack Compose 中进行操作?
【问题讨论】:
标签: android kotlin android-recyclerview android-jetpack-compose
您可以为此使用androidx.ui.foundation.AdapterList。
它只会组合和布置当前可见的项目。
@Composable
fun CustomerListView(list: List<Customer>) {
AdapterList(data = list) { customer->
Text("name:${customer.name}")
}
}
【讨论】:
您可以像 here 解释的那样使用 LazyColumnFor:
@Composable
fun LazyColumnForDemo() {
LazyColumnFor(items = listOf(
"A", "B", "C", "D"
) + ((0..100).map { it.toString() }),
modifier = Modifier,
itemContent = { item ->
Log.d("COMPOSE", "This get rendered $item")
when (item) {
"A" -> {
Text(text = item, style = TextStyle(fontSize = 80.sp))
}
"B" -> {
Button(onClick = {}) {
Text(text = item, style = TextStyle(fontSize = 80.sp))
}
}
"C" -> {
//Do Nothing
}
"D" -> {
Text(text = item)
}
else -> {
Text(text = item, style = TextStyle(fontSize = 80.sp))
}
}
})
}
谷歌在这里解释:https://youtu.be/SMOhl9RK0BA23:18
【讨论】: