所以我尝试遵循 jetpack compose forilarows 的示例
创建惰性行对象时,除非我指定此导入: import androidx.compose.foundation.lazy.items
lazyrow 函数内的 items 函数抛出此错误:类型不匹配:推断类型为 List<DrawableStringPair> 但需要 Int
我相信它会根据输入使用不同的函数,但我试图找出为什么上面的 import 语句修复了它。所有“items”函数都在同一文件“LazyDsl.kt”中定义
我想我的问题是,上面的导入如何指定其此功能:
inline fun <T> LazyListScope.items(
items: List<T>,
noinline key: ((item: T) -> Any)? = null,
noinline contentType: (item: T) -> Any? = { null },
crossinline itemContent: @Composable LazyItemScope.(item: T) -> Unit
) = items(
Run Code Online (Sandbox Code Playgroud)
而不是这个:
fun items(
count: Int,
key: ((index: Int) -> Any)? = null,
contentType: (index: Int) -> Any? = { null },
itemContent: @Composable LazyItemScope.(index: Int) -> Unit …Run Code Online (Sandbox Code Playgroud)