Title: Trying to create a simple recyclerView in Kotlin, but the adapter is not applying properly
Tags: android;android-recyclerview;kotlin
Question: I'm trying to create a simple recyclerView in Kotlin with data that I get via Volley (which I have confirmed returns the correct data), I keep running to the error E/RecyclerView: No adapter attached; skipping layout when in fact I have specified an adapter with the custom adapter class that I created:
class ImageAdapter(var c: Context, var list: ArrayList<Image&gt;) : RecyclerView.Adapter<ImageAdapter.ViewHolder&gt;() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder? {
val layoutInflater = LayoutInflater.from(parent.context)
return ViewHolder(layoutInflater.inflate(R.layout.image_cardview, parent, false))
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val imageUrl = list[position].url
val submitter = list[position].submitter
val color = list[position].color
holder.submitterTV.text = submitter
holder.card.setCardBackgroundColor(Color.parseColor(color))
override fun getItemCount() = list.size
class ViewHolder(itemView: View): RecyclerView.ViewHolder(itemView){
val card = itemView.card
val submitterTV = itemView.submitter
val imageView = itemView.image
This is my MainActivty class, where I make the actual call for the JSON and attempt to attach my adapter with my ArrayList that I have created:
class MainActivity : AppCompatActivity() {
val images = ArrayList<Image&gt;()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
imageList.layoutManager = LinearLayoutManager(applicationContext)
request("https://api.unsplash.com/photos/curated/?client_id=API_KEY")
imageList.adapter = ImageAdapter(applicationContext, images)
private fun request(url: String) {
val queue = Volley.newRequestQueue(this)
val stringRequest = JsonArrayRequest(url, Response.Listener<JSONArray&gt; { response -&gt;
try {
for (i in 0..(response.length() - 1)) {
val image: Image = Image(response.getJSONObject(i).getJSONObject("urls").getString("full"), response.getJSONObject(i).getJSONObject("user").getString("username"), response.getJSONObject(i).getString("color"))
images.add(image)
}
imageList.adapter.notifyDataSetChanged()
} catch (e: JSONException) {
e.printStackTrace()
}
}, Response.ErrorListener { })
queue.add(stringRequest)
I have created a custom data class Image which stores three fields: the imageUrl, submitter and color, all of which are derived from the JSON. I thought that calling notifyDataSetChanged() on my adapter after the request was completed would allow the recyclerView to get updated and show the items, but nothing at all shows up on the screen. Does anyone have any idea as to where I messed up?
Comment: Does the request actually gets returned? I'm not sure about Volley but you're initialising the `val queue` inside the method, then adding a request to that queue, but that queue object would only exist within the scope of the `request()` method, it probably got garbage collected before you get your requests back. Also, don't you need to call `queue.start()` before it does anything?

Comment: Possible duplicate of [recyclerview No adapter attached; skipping layout](http://stackoverflow.com/questions/29141729/recyclerview-no-adapter-attached-skipping-layout)

Comment: What happens, if you set your adapter inside request finished callback?


Here is another answer: try to use Delegate Adapters below is reference link.
Ref Link : https://android.jlelse.eu/keddit-part-4-recyclerview-delegate-adapters-data-classes-with-kotlin-9248f44327f7

Here is another answer: Recyclerview with different listener for different view
AddressAdapter
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
class AddressAdapter (private val listener: (AddressData, Int,Int) -&gt; Unit):
RecyclerView.Adapter<AddressViewHolder&gt;() {
var lstAddress = emptyList<AddressData&gt;()
fun setData(items: List<AddressData&gt;) {
lstAddress = items
notifyDataSetChanged()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AddressViewHolder {
return AddressViewHolder.create(parent)
override fun getItemCount(): Int {
return lstAddress.size
override fun onBindViewHolder(holder: AddressViewHolder, position: Int) {
return holder.bind(lstAddress[position], listener, position)
fun getData(): List<AddressData&gt; {
return lstAddress
AddressViewHolder
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.extensions.LayoutContainer
import kotlinx.android.synthetic.main.item_address.view.*
class AddressViewHolder(override val containerView: View) :
RecyclerView.ViewHolder(containerView), LayoutContainer {
companion object {
fun create(parent: ViewGroup): AddressViewHolder {
val view =
LayoutInflater.from(parent.context)
.inflate(R.layout.item_address, parent, false)
return AddressViewHolder(view)
fun bind(
item: AddressData,
listener: (AddressData, Int,Int) -&gt; Unit,
position: Int
item.address.let {
itemView.tvAddress.text = it
itemView.tvEdit.setOnClickListener {
listener.invoke(item, position,R.id.tvEdit)
itemView.tvDelete.setOnClickListener {
listener.invoke(item, position,R.id.tvDelete)
itemView . tvAddress . setOnClickListener {
listener.invoke(item, position, R.id.tvAddress)
item_address
<?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;&gt;
<androidx.appcompat.widget.AppCompatTextView
android:id=&quot;@+id/tvWorkPlace&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_alignParentStart=&quot;true&quot;
android:layout_alignParentTop=&quot;true&quot;
android:layout_marginStart=&quot;@dimen/letter_medium&quot;
android:layout_marginTop=&quot;@dimen/letter_medium&quot;
android:gravity=&quot;top&quot;
android:text=&quot;@string/work_place&quot;
android:textColor=&quot;@color/black_color&quot;
android:textSize=&quot;@dimen/letter_medium&quot;
android:textStyle=&quot;bold&quot;
app:layout_constraintStart_toStartOf=&quot;parent&quot;
app:layout_constraintTop_toTopOf=&quot;parent&quot; /&gt;
<androidx.appcompat.widget.AppCompatTextView
android:id=&quot;@+id/tvDefault&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_alignParentTop=&quot;true&quot;
android:layout_marginStart=&quot;@dimen/spacing_medium&quot;
android:text=&quot;@string/txt_default&quot;
android:textColor=&quot;#002D56&quot;
android:textSize=&quot;@dimen/letter_small&quot;
app:layout_constraintBottom_toBottomOf=&quot;@+id/tvWorkPlace&quot;
app:layout_constraintStart_toEndOf=&quot;@+id/tvWorkPlace&quot;
app:layout_constraintTop_toTopOf=&quot;@+id/tvWorkPlace&quot; /&gt;
<androidx.appcompat.widget.AppCompatTextView
android:id=&quot;@+id/tvAddress&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_alignParentTop=&quot;true&quot;
android:layout_marginTop=&quot;@dimen/spacing_small&quot;
android:text=&quot;76 Playfair Road, #04-06, LHK2, Singapore 367996&quot;
android:textSize=&quot;@dimen/letter_small&quot;
app:layout_constraintStart_toStartOf=&quot;@+id/tvWorkPlace&quot;
app:layout_constraintTop_toBottomOf=&quot;@+id/tvWorkPlace&quot; /&gt;
<androidx.appcompat.widget.AppCompatTextView
android:id=&quot;@+id/tvEdit&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_alignParentTop=&quot;true&quot;
android:layout_marginTop=&quot;@dimen/spacing_large&quot;
android:text=&quot;@string/txt_edit&quot;
android:textAllCaps=&quot;true&quot;
android:textColor=&quot;@color/colorSecondary&quot;
android:textSize=&quot;@dimen/letter_small&quot;
android:textStyle=&quot;bold&quot;
app:layout_constraintStart_toStartOf=&quot;@+id/tvAddress&quot;
app:layout_constraintTop_toBottomOf=&quot;@+id/tvAddress&quot; /&gt;
<androidx.appcompat.widget.AppCompatTextView
android:id=&quot;@+id/tvDelete&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_alignParentTop=&quot;true&quot;
android:layout_marginStart=&quot;@dimen/spacing_large&quot;
android:text=&quot;@string/txt_delete&quot;
android:textAllCaps=&quot;true&quot;
android:textColor=&quot;@color/colorPrimaryNew&quot;
android:textSize=&quot;@dimen/letter_small&quot;
android:textStyle=&quot;bold&quot;
app:layout_constraintStart_toEndOf=&quot;@+id/tvEdit&quot;
app:layout_constraintTop_toTopOf=&quot;@+id/tvEdit&quot; /&gt;
<View
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;0.2dp&quot;
android:layout_marginTop=&quot;@dimen/spacing_medium&quot;
android:background=&quot;@color/divider_color&quot;
app:layout_constraintTop_toBottomOf=&quot;@+id/tvDelete&quot; /&gt;
</androidx.constraintlayout.widget.ConstraintLayout&gt;
AddressData
class AddressData (
var code: Int,
var address:String
In Activity
private fun setUpAdapter() {
adapter = AddressAdapter(fun(item: AddressData, position: Int, type: Int) {
when (type) {
R.id.tvEdit -&gt; {
context.showToast(
&quot;Editbtn&quot; + position,
showInReleaseBuild = true
)
}
R.id.tvDelete -&gt; {
context.showToast(
&quot;Deletebtn&quot; + position,
showInReleaseBuild = true
)
}
R.id.tvAddress -&gt; {
context.showToast(
&quot;addressbtn&quot; + position,
showInReleaseBuild = true
)
}
}
})
rvAddress.adapter = adapter
rvAddress.setEmptyView(llEmptyViewMain)
val addressData = AddressData(1, &quot;abcd&quot;)
val addressData1 = AddressData(2, &quot;abceeed&quot;)
lstData = listOf(addressData, addressData1)
adapter.setData(lstData)
CustomRecycler Xml
<com.example.views.CustomRecyclerView
android:id=&quot;@+id/rvAddress&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;match_parent&quot;
android:layout_marginStart=&quot;@dimen/mediumSize&quot;
android:layout_marginTop=&quot;@dimen/mediumSize&quot;
android:layout_marginEnd=&quot;@dimen/mediumSize&quot;
app:layoutManager=&quot;androidx.recyclerview.widget.LinearLayoutManager&quot;
app:list_type=&quot;list&quot;
tools:listitem=&quot;@layout/item_address&quot; /&gt;
<include layout=&quot;@layout/layout_recycler_emptyview&quot; /&gt;

Here is another answer: You can download the source code from here(Recyclerview In Kotlin Android)
MainActivity.kt:
package com.deepshikha.recyclerviewkotlin
import android.app.Activity
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.view.Window
import android.view.WindowManager
import android.widget.LinearLayout
import kotlinx.android.synthetic.main.activity_main.*
import net.simplifiedcoding.recyclerviewexample.CustomAdapter
class MainActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
requestWindowFeature(Window.FEATURE_NO_TITLE)
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)
setContentView(R.layout.activity_main)
val users = ArrayList<Model_Details&gt;()
users.add(Model_Details("Kaju katli", "Kaju katli, also known as kaju Katari or kaju barfi, is an Indian dessert similar to a barfi.",R.drawable.kaju))
users.add(Model_Details("Doughnut", "The doughnut is popular in many countries and prepared in various forms as a sweet snack that can be homemade or purchased in bakeries, supermarkets, food stalls, and franchised specialty outlets",R.drawable.donuts))
users.add(Model_Details("Panna cotta", "Panna cotta is an Italian dessert of sweetened cream thickened with gelatin and molded. The cream may be aromatized with rum, coffee, vanilla, or other flavorings.",R.drawable.panna_cotta))
users.add(Model_Details("Rose Cookies", "Rose cooky is a famous South Indian snack made during festivals",R.drawable.rosecookies))
users.add(Model_Details("Belgian waffle", "In North America, Belgian waffles are a variety of waffle with a lighter batter, larger squares, and deeper pockets than ordinary American waffles",R.drawable.belgianwaffle))
val obj_adapter = CustomAdapter(users)
recyclerView.layoutManager = LinearLayoutManager(this, LinearLayout.VERTICAL, false)
recyclerView.adapter = obj_adapter
CustomAdapter.kt:
package net.simplifiedcoding.recyclerviewexample
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.deepshikha.recyclerviewkotlin.Model_Details
import com.deepshikha.recyclerviewkotlin.R
import kotlinx.android.synthetic.main.adapter_details.view.*
class CustomAdapter(val userList: ArrayList<Model_Details&gt;) : RecyclerView.Adapter<CustomAdapter.ViewHolder&gt;() {
//this method is returning the view for each item in the list
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CustomAdapter.ViewHolder {
val v = LayoutInflater.from(parent.context).inflate(R.layout.adapter_details, parent, false)
return ViewHolder(v)
//this method is binding the data on the list
override fun onBindViewHolder(holder: CustomAdapter.ViewHolder, position: Int) {
holder.bindItems(userList[position])
//this method is giving the size of the list
override fun getItemCount(): Int {
return userList.size
//the class is hodling the list view
class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
fun bindItems(user: Model_Details) {
itemView.tv_name.text=user.name
itemView.tv_des.text=user.des
itemView.iv_name.setImageResource(user.image)
}
Thanks!
Comment for this answer: but no example of how to get an item inside the adapter
Comment for this answer: in MainActivity where is the recyclerView var initialized?
Comment for this answer: I see it called with .apply and .layoutManager, but where is it coming from... I'm missing something.
Comment for this answer: Most simplistic and minimalist example ever.
Comment for this answer: @Gabriel Fernandez I don't understand what you mean but I'm pretty sure rakeshdas didn't ask about it.

Here is another answer: On .MainActivity.kt
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
//rcv is id of Recyclerview
rcv.layoutManager = LinearLayoutManager(this)
rcv.adapter = MyAdpater()
Create a new .kt file for creating Adapter
class MyAdpater : RecyclerView.Adapter<ViewHolder&gt;() {
val arr = listOf("A", "B", "C", "D", "E") //static array
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.textView.setText(arr.get(position)) //set text to textview by position
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return ViewHolder(TextView(parent.context))
override fun getItemCount(): Int {
return arr.count() //return array count
class ViewHolder(val textView: TextView): RecyclerView.ViewHolder(textView){ //ViewHolder with textview}

Here is another answer: I have my RecyclerView Adapter which is as follows,
internal class OptionsAdapter : RecyclerView.Adapter<OptionsAdapter.ViewHolder&gt;() {
private val mOptionList = ArrayList<Option&gt;()
private var mOnItemClickListener: OnItemClickListener<Option&gt;? = null
var data: List<Option&gt;
get() = mOptionList
set(list) {
mOptionList.clear()
mOptionList.addAll(list)
notifyDataSetChanged()
fun setOnItemClickListener(listener: OnItemClickListener<Option&gt;) {
mOnItemClickListener = listener
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return ViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.layout_text, parent, false))
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val option = getItem(position)
holder.textViewOption.setText(option.text)
holder.textViewDescription.setText(option.subText)
private fun getItem(index: Int): Option {
return mOptionList[index]
override fun getItemCount(): Int {
return mOptionList.size
internal inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
var textViewOption: TextView
var textViewDescription: TextView
var imageViewOptionIcon: ImageView
init {
textViewOption = itemView.findViewById<TextView&gt;(R.id.textview_option)
imageViewOptionIcon = itemView.findViewById<ImageView&gt;(R.id.imageview_option_icon)
textViewDescription = itemView.findViewById<TextView&gt;(R.id.textview_description)
itemView.setOnClickListener {
if (mOnItemClickListener != null) {
mOnItemClickListener!!.onItemClick(getItem(adapterPosition))
}
}
Comment for this answer: private fun getItem is not accessible to use

Here is another answer: I have created a nice adapter may be it helped in reducing code..
class ResultActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.question_list_activity)
if (intent != null) {
var results = intent.getParcelableArrayListExtra<Parcelable&gt;("keyResults") as ArrayList<ResultBO&gt;
if (results.size &gt; 0) {
recycler_view.adapter = ResultAdapter(results, object : OnRecyclerItemClickListener {
override fun onItemClicked(view: View?, position: Int) {
/*var intent = Intent(this@SubjectListActivity,McqActivity75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0lass.java)
intent.putExtra("keyTagBO",subjects.get(position))
startActivity(intent)*/
}
});
}
}
item_result.xml
<?xml version="1.0" encoding="utf-8"?&gt;
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"&gt;
<TextView
android:id="@+id/titleTv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Dummy Value"
android:textAlignment="center"
android:textAppearance="@style/TextAppearance.AppCompat.Large" /&gt;
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal"&gt;
<TextView
android:id="@+id/option1Tv"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Dummy"
android:textAlignment="center"
android:textAppearance="@style/TextAppearance.AppCompat.Medium" /&gt;
<TextView
android:id="@+id/option2Tv"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Dummy Value"
android:textAlignment="center"
android:textAppearance="@style/TextAppearance.AppCompat.Medium" /&gt;
</LinearLayout&gt;
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal"&gt;
<TextView
android:id="@+id/option3Tv"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Dummy"
android:textAlignment="center"
android:textAppearance="@style/TextAppearance.AppCompat.Medium" /&gt;
<TextView
android:id="@+id/option4Tv"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Dummy Value"
android:textAlignment="center"
android:textAppearance="@style/TextAppearance.AppCompat.Medium" /&gt;
</LinearLayout&gt;
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"&gt;
</LinearLayout&gt;
</LinearLayout&gt;
ResultADapter.class
class ResultAdapter(items: List<ResultBO&gt;, onRecyclerItemClickListener: OnRecyclerItemClickListener) : BaseAdapter<ResultBO, ResultViewHolder&gt;(items, onRecyclerItemClickListener) {
override fun onCreateViewHolder(parent: ViewGroup, pos: Int): ResultViewHolder {
return ResultViewHolder(parent, R.layout.item_result,onRecyclerItemClickListener)
BaseViewHolder.class
abstract class BaseViewHolder<T : BaseModel&gt;(parent: ViewGroup, @LayoutRes itemLayoutId: Int,
var onRecyclerItemClickListener: OnRecyclerItemClickListener) :
RecyclerView.ViewHolder(LayoutInflater.from(parent.context).inflate(itemLayoutId, parent,
false)), View.OnClickListener {
override fun onClick(v: View?) {
onRecyclerItemClickListener.onItemClicked(v, adapterPosition)
abstract fun bindData(data: T)
init {
itemView.setOnClickListener(this)
BaseAdapter
abstract class BaseAdapter<T : BaseModel, U : BaseViewHolder<T&gt;&gt;
(var items: List<T&gt;, var onRecyclerItemClickListener: OnRecyclerItemClickListener)
: RecyclerView.Adapter<U&gt;() {
override fun getItemCount(): Int {
return items.size
override fun onBindViewHolder(holder: U, pos: Int) {
holder.bindData(items.get(pos))
ResultViewHolder.class
class ResultViewHolder(parent: ViewGroup, itemLayoutId: Int, onRecyclerItemClickListener: OnRecyclerItemClickListener) : BaseViewHolder<ResultBO&gt;(parent, itemLayoutId, onRecyclerItemClickListener) {
override fun bindData(data: ResultBO) {
itemView.titleTv.setText(data.questionBO.title)
itemView.option1Tv.setText(data.questionBO.options.get(0))
itemView.option2Tv.setText(data.questionBO.options.get(1))
itemView.option3Tv.setText(data.questionBO.options.get(2))
itemView.option4Tv.setText(data.questionBO.options.get(3))
when(data.orignalAnswer()) {
OptionType.A -&gt; itemView.option1Tv.setBackgroundColor(Color.GREEN)
OptionType.B -&gt; itemView.option2Tv.setBackgroundColor(Color.GREEN)
OptionType.C -&gt; itemView.option3Tv.setBackgroundColor(Color.GREEN)
OptionType.D -&gt; itemView.option4Tv.setBackgroundColor(Color.GREEN)
}
if(!data.isCorrectlyAnswered()){
when(data.selectedOption) {
OptionType.A -&gt; itemView.option1Tv.setBackgroundColor(Color.RED)
OptionType.B -&gt; itemView.option2Tv.setBackgroundColor(Color.RED)
OptionType.C -&gt; itemView.option3Tv.setBackgroundColor(Color.RED)
OptionType.D -&gt; itemView.option4Tv.setBackgroundColor(Color.RED)
}
}

Here is another answer: Look at following example, I think you this can give you an idea.
You can get the example from here : https://github.com/Siddharha/RecyclerviewTest_Kotlin
Main Activity
class MainActivity : AppCompatActivity() {
private var myAdapter: MyAdapter? = null
private var arrayList: ArrayList<MyItem&gt;? = null
private var layoutManager: RecyclerView.LayoutManager? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
initialize()
setupList()
loaddata()
private fun loaddata() {
for (i in 0..9) {
val myItem = MyItem()
myItem.name = "Sid_" + i
myItem.number = "098899876" + i
arrayList!!.add(myItem)
myAdapter!!.notifyDataSetChanged()
private fun setupList() {
rlItems!!.layoutManager = layoutManager
rlItems!!.adapter = myAdapter
private fun initialize() {
arrayList = ArrayList<MyItem&gt;()
layoutManager = LinearLayoutManager(this, LinearLayout.VERTICAL, false)
myAdapter = MyAdapter(arrayList!!, this, R.layout.item_cell)
Adapter Class
internal class MyAdapter(private val arrayList: ArrayList<MyItem&gt;,
private val context: Context,
private val layout: Int) : RecyclerView.Adapter<MyAdapter.ViewHolder&gt;() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyAdapter.ViewHolder {
val v = LayoutInflater.from(parent.context).inflate(layout, parent, false)
return ViewHolder(v)
override fun onBindViewHolder(holder: MyAdapter.ViewHolder, position: Int) {
holder.bindItems(arrayList[position])
override fun getItemCount(): Int {
return arrayList.size
internal inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
fun bindItems(items: MyItem) {
itemView.tvName.text = items.name
itemView.tvNumber.text = items.number
Item Class
internal class MyItem {
var name: String? = null
var number: String? = null

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 7, 'CommentCount': 3, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2017:00:03/25/17', 'FavoriteCount': 1.0, 'PostTypeId': 1, 'Tags': '<android><android-recyclerview><kotlin>', 'Title': 'Trying to create a simple recyclerView in Kotlin, but the adapter is not applying properly', 'ViewCount': 46596, 'id': 43012903, 'user_AboutMe': None, 'user_AccountId': 3919328.0, 'user_DisplayName': 'rakeshdas', 'user_Reputation': 2193.0, 'user_Views': 179.0, 'user_id': 3749128.0}}