[英]Why items captured object giving me No reference found in Compose
I've a data class:我有一个数据 class:
data class Feed_Status(val img:Int, val name_id: String)
I've a class:我有一个 class:
class Feed_helper {
fun Image_getter(): List<() -> Feed_Status> {
val Images = listOf {
Feed_Status(R.drawable.image_demo1, "name1")
Feed_Status(R.drawable.image_demo2, "name2")
Feed_Status(R.drawable.image_demo3, "name3")
Feed_Status(R.drawable.image_demo4, "name4")
Feed_Status(R.drawable.image_demo5, "name5")
Feed_Status(R.drawable.image_demo6, "name6")
Feed_Status(R.drawable.image_demo7, "name7")
Feed_Status(R.drawable.image_demo8, "name8")
Feed_Status(R.drawable.image_demo9, "name9")
Feed_Status(R.drawable.image_demo10, "name10")
Feed_Status(R.drawable.image_demo11, "name11")
Feed_Status(R.drawable.image_demo12, "name12")
Feed_Status(R.drawable.image_demo13, "name13")
Feed_Status(R.drawable.image_demo14, "name14")
Feed_Status(R.drawable.image_demo15, "name15")
Feed_Status(R.drawable.image_demo16, "name16")
Feed_Status(R.drawable.image_demo17, "name17")
Feed_Status(R.drawable.image_demo18, "name18")
Feed_Status(R.drawable.image_demo19, "name19")
Feed_Status(R.drawable.image_demo20, "name20")
Feed_Status(R.drawable.image_demo21, "name21")
Feed_Status(R.drawable.image_demo22, "name22")
Feed_Status(R.drawable.image_demo23, "name23")
Feed_Status(R.drawable.image_demo24, "name24")
Feed_Status(R.drawable.image_demo25, "name25")
Feed_Status(R.drawable.image_demo25, "name26")
}
return Images
}
}
through which I'm calling items()
in lazyRow
通过它我在lazyRow
中调用items()
@Composable
fun feed() {
LazyColumn(
reverseLayout = false,
modifier = Modifier
.fillMaxSize(),
userScrollEnabled = true
) {
// Status(es)
item {
LazyRow(
reverseLayout = false,
modifier = Modifier
.fillMaxWidth()
.height(100.dp),
horizontalArrangement = Arrangement.SpaceBetween,
userScrollEnabled = true
) {
val statuses = Feed_helper().Image_getter()
items(statuses) { status ->
Column(
verticalArrangement = Arrangement.Center,
modifier = Modifier
.width(80.dp)
) {
Card(
shape = CircleShape,
modifier = Modifier
.padding(8.dp)
.size(64.dp)
) {
Image(
painterResource(id = status.img),
contentDescription = status.name_id + "'s status",
contentScale = ContentScale.Crop
)
}
Text(
text = status.name_id,
modifier = Modifier.fillMaxWidth(),
textAlign = TextAlign.Center,
)
}
}
}
}
}
}
But whenever I'm calling element from statuses
through statuses
in items()
it is giving me Reference Not found!但是每当我通过items()
中的statuses
从statuses
中调用元素时,它都会给我 Reference Not found!
Callers:来电者:
painterResource(id = status.img)
in Image()
Image()
中的painterResource(id = status.img)
)
contentDescription = status.name_id + "'s status"
in Image()
contentDescription = status.name_id + Image()
中contentDescription = status.name_id + "'s status"
text = status.name_id
in Text
文本 = Text
中的text = status.name_id
All callers are in items(statuses){ status ->
所有来电者都在items(statuses){ status ->
I've been trying to solve this for hours.几个小时以来,我一直在努力解决这个问题。 So any help will be very apreciated.因此,我们将不胜感激任何帮助。
If you find any typo please update it or tell me to fix.如果您发现任何拼写错误,请更新它或告诉我修复。
PS: This is my first time here and I have an almost zero experience on android development and Kotlin. I developed terminal apps and worked on ML kinda work in Python, C++, C. So I may need more information in explanation. PS:这是我第一次来这里,我对 android 开发和 Kotlin 的经验几乎为零。我在 Python、C++、C 开发了终端应用程序并从事 ML kinda 工作。所以我可能需要更多信息来解释。 I started learning Android Development a week ago only.我一周前才开始学习 Android 开发。
Edit: You can ask me any more information.编辑:你可以问我更多信息。
Peace和平
Change the return type of Image_getter
to List<Feed_status>
instead of it having a type of lambda, and change the braces to parenthesis when you declare the list of them.将Image_getter
的返回类型更改为List<Feed_status>
而不是其类型为 lambda,并在声明它们的列表时将大括号更改为圆括号。
class Feed_helper {
fun Image_getter(): List<Feed_Status> { // change it to this instead of type of lambda `() -> Feed_status`
val Images = listOf ( // change it to this instead of braces
...
)
return Images
}
}
and import并导入
import androidx.compose.foundation.lazy.items
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.