From the course: Android Compose with Kotlin
Unlock this course with a free trial
Join today to access over 24,800 courses taught by industry experts.
Handle lazy layout item click events - Kotlin Tutorial
From the course: Android Compose with Kotlin
Handle lazy layout item click events
- [Instructor] When a user clicks on one of the sessions, we want to navigate them to the session detail screen. Let's see how this is done with our view-based app. Starts with the SessionItemAdapter. Here on line number 12, we take in a click listener. And then here on line number 37, we make a call to it with our root's setOnClickListener function. Then, over in the SessionsFragment, we've defined what should happen when one of the sessions is clicked on. So first, on line 69, we make a call to the viewModel's setSelectedSessionId, and then we use our navController to navigate to the global SessionDetailFragment. Let's see how to reproduce this with compose. Now, our viewModel is already prepared to fetch a given session by its ID, so our job is to provide a path from our navigation hosts to our session detail screen. Let's start with the SessionsScreen. So we'll move over to the SessionsScreen, and using the pattern of state hoisting, we're going to take in a callback. And let's…
Contents
-
-
-
-
-
-
-
-
(Locked)
Explore lazy layouts in Compose5m 47s
-
(Locked)
Add a LazyGrid to a composable screen6m 24s
-
(Locked)
Handle lazy layout item click events4m 11s
-
(Locked)
Handle loading and empty states7m 53s
-
(Locked)
Display snackbar messages6m 4s
-
(Locked)
Pass data in a ViewModel3m 54s
-
(Locked)
Challenge: Adding some polish1m 36s
-
(Locked)
Solution: Adding some polish2m 9s
-
(Locked)
-
-
-