RecyclerView Adapter Android in Kotlin

In android recycler view is most commonly used and is important in almost all kinds of projects that’s why it is considered as the basic of android development.

Until unless we don’t understand the concept of working of android studio we can’t deal with it.
Once a recycler view concept is cleared anyone can do any customisation in data listing

Let’s move toward the topic first of all we have to discuss the basis of recycler view.

make the layout_custom.xml file to get ready your user interface

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android=""

android:textStyle="bold" />


Make a kotlin class for adapter and pass data that you want to use in the adapter as constructer parameter
We need a view holder class to bind the view with the adapter
In the next step extend this class with the recycler view adapter and typecast this adapter to the view holder class that you have created.

Implement the built in functions by ALT+ENTER.

class MyCustomAdapter(
val mContext: BaseActivity,
val mData: ArrayList<Any>,
val callBack: (position: Int, item: Any) -> Unit
) : RecyclerView.Adapter<MyViewHolder>() {

interface OnClickListener {
fun onItemClick(position: Int)

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
val view = LayoutInflater.from(context)
.inflate(R.layout.layout_custom, parent, false)
return MyViewHolder(view)

override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
val item = mData[position]
//Do your work here
holder.binding.tvTitle.text = item.title
//and for callback
override fun getItemCount() = mData.count()
class MyViewHolder(ItemView: View):RecyclerView.ViewHolder(ItemView){
val binding:LayoutCustomBinding?=DataBindingUtil.bind(itemView)}

In case if you are not using data binding then simply use RecyclerView.ViewHolder everywhere instead of MyViewHolder

here onCreateViewHolder is returning your view to the adapter
getItemCount is simply returning your array count
onBindViewHolder to to set your data over the xml and for other actions like controlling the clicks and conditions , all your work will be done in this method

var mAdapter = MyCustomAdapter(this,mData){position,item->
recyclerView.layoutManager = LinearLayoutManager(this, RecyclerView.VERTICAL, false)
recyclerView.adapter = mAdapter
//all set now when you do any change in the data just call notifydataset changed




Being a mobile application developer I decided to write some useful content for those who are freshers in the fields and looking for helping material.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Android Code to save image in Internal Storage on button click

How to determine which Fragment is being Displayed in the Activity

How to create a Phone Call App in Kotlin Android?

11 Things You Should Know When Starting Android Development

Easy RecyclerView With DiffUtill and DataBiding(Kotlin)

How to add Cloud function in Android ?

Managing and Testing Translations in Android applications.

10 Flutter tips part — 4/10

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Munib Hamza

Munib Hamza

Being a mobile application developer I decided to write some useful content for those who are freshers in the fields and looking for helping material.

More from Medium

Android ViewModel

Make a simple RecyclerView in Android with Kotlin

View Binding in Android.

Kotlin Coroutines [Part-1]