Android RecyclerView in Kotlin

How to create recyclerview in android kotlin?

Hüseyin Özkoç
2 min readNov 29, 2021
Android RecyclerView in Kotlin

Hello! Welcome to my article Dear Android Developers! and Dear Predators! Today, I am going to talk about creating Recyclerview in Android with Kotlin.

There are four main part of the creating Recyclerview.
1-Creating Model Class
2-Creating Row Layout according to model
3-Creating Adapter Class
4-Filling RecyclerView with related data.

First of all, we should begin with creating our model class for data.

Then, we should create appropriate layout for our row data and fill inside of the layout according to our model class.

Now, we have to compose our Adapter class. There are three distinctive method that we have to implement to the adapter class.

1-onCreateViewHolder()

2-onBindViewHolder()

3-getItemCount()

Add inner class of the adapter which is ModelViewHolder.

Reach our views from ModelViewHolder class.

Inflate our layout inside of the oncreateViewHolder() method.

Add our data list into the adapter class.

Bind view with their data using our list in onBindViewHolder().

Set Item count for recyclerview with using our list size.

Here is the full code of the our adapter class :

Now let’s set main activity layout and add recyclerview to main activity.

Before the filling our recyclerview, set your mock data in the model class.

Add new data into the List.

Make setting of our recyclerview inside of the main activity.

And! TADAAAAAA!

Android RecyclerView in Kotlin

I hope it was a useful article. See you in my other articles!

Photo by Wes Hicks on Unsplash

--

--