Simple Recyclerview Kotlin

Vignesh Theagarajan
2 min readMay 16, 2019

--

Today we are going create the Recyclerview in Kotlin with very simple and fewer lines of code.

To create a Recyclerview we need to create

  • Create a Simple Data class
  • Create RecyclerAdapter
  • Create ViewHolder
I have created a video tutorial for this post but its in Tamil language.

Create a Simple Data class

Create a data class SimpleAdapter.kt with the code below .just look at the Data class how kotlin helps us to reduce boilerplate code. Setter getter also not required here.

Create RecyclerView Adapter and ViewHolder

Create SimpleAdapter.kt file with the code below. This Kotlin file contains two classes, SimpleAdapter class which takes an ArrayList of SeriesModel and send it layout_cell.xml to show. And The ViewHolder will assign the values from the model to their corresponding views.

MainActivity

It is the main Kotlin Activity which creates the RecyclerView. In this class we create a simple ArrayList For Contact in a single line for loop. How Kotlin reduced boilerplate codes. This data are displayed in the list and then we pass this array of elements to MyAdapter class(the source code of which is right above), to display the content of our ArrayList.

The final output would be like this.sorry for the bad UI. Didn't spend much time on it.

If you have any questions or comments, feel free to comment below.

Will update the source code for GitHub soon here.

--

--

Vignesh Theagarajan
Vignesh Theagarajan

Written by Vignesh Theagarajan

android developer. Decently chubby guy. Wears glasses. Has a beard. Thinks he’s funny. Loves food a lot more than he should. http://vigneshtheagarajan.com/