最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

android - How do I iterate over a Map List in LazyRow? - Stack Overflow

programmeradmin1浏览0评论

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
Add a comment  | 

1 Answer 1

Reset to default 0

There 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.

发布评论

评论列表(0)

  1. 暂无评论