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

Unlock the full course today

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

Create a RecyclerView adapter class

Create a RecyclerView adapter class

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

Start my 1-month free trial

Create a RecyclerView adapter class

- [Instructor] An adapter class is designed to receive data and then apply it to each item in a recycler view. It has many different parts and it takes a bit of coding, but I'll explain each part as we go. I'm going to create this adapter class in my ui.main package, because it's specifically designed to be used in the main fragment. I'll create a new Kotlin class and I'll name it Main Recycler Adapter. The primary constructor for this class will receive two arguments. They'll both start with the val keyword, so that they persist for the lifetime of the adapter. The first will be a Context and the second will be the data that's being passed in. And I'll simply call that monsters, this will be a list of monster objects. Make sure to import each class or interface as you need to. This class will be extended from a class called RecyclerView.adapter. It has a generic notation and I'm going to reference a class that doesn't exist yet, it'll be called view holder and it'll be an inner class…

Contents