admin管理员组文章数量:1315312
I'm trying to get the images from the CatModel into my LayzColumn. But I don't know how because I have a map list
LazyRow(
horizontalArrangement = Arrangement.spacedBy(8.dp),
contentPadding = PaddingValues(horizontal = 16.dp),
modifier = Modifier.fillMaxWidth()
)
{
items(dish.integrates.entries.toList()) { entry ->
AsyncImage(
model = entry.value.imageUrl,
contentDescription = null,
modifier = Modifier.size(50.dp),
contentScale = ContentScale.Crop
)
}
}
DishDetailModel.kt:
data class DishDetailModel(
var title: String? = null,
var description: String? = null,
var image: String? = null,
var time: String? = null,
var category: ArrayList<String> = ArrayList(),
var integrates: Map<String, CastModel>
) : Serializable
CastModel.kt:
data class CastModel(
var castName: String? = null,
var imageUrl: String? = null
) : Serializable
I'm trying to get the images from the CatModel into my LayzColumn. But I don't know how because I have a map list
LazyRow(
horizontalArrangement = Arrangement.spacedBy(8.dp),
contentPadding = PaddingValues(horizontal = 16.dp),
modifier = Modifier.fillMaxWidth()
)
{
items(dish.integrates.entries.toList()) { entry ->
AsyncImage(
model = entry.value.imageUrl,
contentDescription = null,
modifier = Modifier.size(50.dp),
contentScale = ContentScale.Crop
)
}
}
DishDetailModel.kt:
data class DishDetailModel(
var title: String? = null,
var description: String? = null,
var image: String? = null,
var time: String? = null,
var category: ArrayList<String> = ArrayList(),
var integrates: Map<String, CastModel>
) : Serializable
CastModel.kt:
data class CastModel(
var castName: String? = null,
var imageUrl: String? = null
) : Serializable
Share
Improve this question
asked Jan 30 at 9:16
Captai-NCaptai-N
1,5345 gold badges22 silver badges41 bronze badges
1
- Please edit the question and explain what the actual problem is. Are you getting error messages? If so, please provide them as well. – tyg Commented Jan 30 at 9:45
1 Answer
Reset to default 0There are multiple items
functions. You probably use the wrong one, resulting in this error:
Type mismatch: inferred type is List<Map.Entry<String, CastModel>> but Int was expected
The LazyListScope (the environment the LazyRow lambda provides) only has a version that takes an Int
(the number of items) as a parameter. There are other items
functions, but they are declared elsewhere, as extension functions. To use them they must explicitly be imported.
When you place the cursor at items
and press Alt+Space you see a list of available functions. Choose the one that takes a List and the following import statement should be generated:
import androidxpose.foundation.lazy.items
The code should compile fine now.
本文标签: androidHow do I iterate over a Map List in LazyRowStack Overflow
版权声明:本文标题:android - How do I iterate over a Map List in LazyRow? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741977009a2408182.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论