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.