From the course: Android Development Essential Training: Manage Data with Kotlin

Unlock the full course today

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

Handle RecyclerView click events

Handle RecyclerView click events

From the course: Android Development Essential Training: Manage Data with Kotlin

Start my 1-month free trial

Handle RecyclerView click events

- [Instructor] In my app, when the user clicks or presses on a RecyclerView's data item an un-click event is dispatched. I'm going to handle that event in the RecyclerView but the eventual action has to be taken by the parent, an activity or a fragment and to communicate between the adapter and in this case the fragment, I'll need an interface that the fragment implements. There are a number of steps to this and I'll explain them each as we go along. I'm starting the work in the adapter class and down at the bottom, I'll define a new interface. It can be named anything you like, I'll name mine MonsterItemListener. It'll have a single function declaration named onMonsterItemClick and it'll receive a single argument, an instance of the monster class that I'll simply call Monster. Now in my fragment I'll implement that interface. I'll go to the top of the class declaration and I'll add a comma here and then I'll add MonsterItemListener which expands to the full signature…

Contents