AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Kotlin list example10/14/2023 ![]() This example shows how even complex operations can be performed easily with Kotlin’s powerful APIs. We’re making use of the with scope function here to keep our code tidy. Val shipments = mapOf("Chocolate" to 3, "Strawberry" to 7, "Rocky Road" to 5) We’ll subtract all the entries in the sales map and then add all the entries from the shipments map to update each flavor’s Quantity: val sales = mapOf("Vanilla" to 7, "Chocolate" to 4, "Strawberry" to 5) After a day of receiving shipments and selling ice cream, we need to update our store’s inventory map. The forEach method performs an action on each entry in a given map. You can customize the UI of each item by modifying the CustomListItem function.As a final example, we’ll use what we’ve learned already and introduce the forEach method. This will display a list of three items with the text "Item 1", "Item 2", and "Item 3". We also define a list of profiles that we want to display in our custom. You can use this CustomListView function in your app by passing it a list of items to display: val items = listOf("Item 1", "Item 2", "Item 3") CustomListView(items = items) In this example, we define a Profile data class that represents a profile with a name, address, email and image resource ID. In this example, we simply display the text of the item using a Text composable. ![]() The CustomListItem function is where you can define the UI for each item in the list. ![]() It uses a Laz圜olumn to display the list of items and passes each item to the CustomListItem composable function. In this example, we define a CustomListView composable function that takes a list of strings as a parameter. ![]() ![]() Simple Example - fun MyList(items: List) It is similar the RecyclerView in Android. Custom ListView Laz圜olumn Example in Jetpack Compose Laz圜olumn ![]()
0 Comments
Read More
Leave a Reply. |