From the course: Building an Android App with Jetpack Libraries

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Handle a click event on a list item

Handle a click event on a list item - Android Tutorial

From the course: Building an Android App with Jetpack Libraries

Start my 1-month free trial

Handle a click event on a list item

- [Instructor] When the user taps or clicks on a note in the list fragment, it means they want to view that note's text in the editor fragment. I add code to handle the click event in the adapter, and then I'll use the navigation component to display the editor fragment. First, I need to set up a relationship between the data item being clicked and the fragment that does the navigating. I'll add an interface to the adapter class. I'll place this at the bottom of all of the functions. I'll use the keyword interface and then give it a name of ListItemListener. And initially, this will have just one abstract function. I'll name it onItemClick. And when I call that function from the listener object, I'll pass the current noteId and that's an integer. Now, I need to reference to a listener object. So I'm going to change the signature of my adapter class. I'll add a new parameter here and I'll make it a private immutable variable.…

Contents