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
From the course: Android Development Essential Training: Manage Data with Kotlin
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
-
-
-
-
-
-
(Locked)
Handle RecyclerView click events4m 7s
-
Create and navigate to a detail fragment4m 14s
-
(Locked)
Add an Up button to a secondary fragment4m 47s
-
(Locked)
Pass data in a shared ViewModel5m 10s
-
(Locked)
Display details with data binding6m 15s
-
(Locked)
Customize data bindings with an adapter5m 14s
-
(Locked)
-
-
-
-