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

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