How define an adapter with onClickListener inside a companion object?

51 Views Asked by At

I am taking a list and a name from user in other activity and i want to pass this values to other item and this item to a recyclerview when i turn back to MainActivity.

I tried companion objects but i wasnt be able to acces variables outside of it. So i create variables inside the companion object but in this time while creating adapter there was an error. While definening in MainActivity i wrote to listener parameter "this" keyword but in here it gives an error.

companion object{
       var listSize = 0
       val recyclerViewItems = ArrayList<Itemclass>()
       val adapter = Adapter(recyclerViewItems,this)

       fun addItem(name:String, list:ArrayList<QuestionItemClass>){
           val index = listSize

           val itemToAdd = Itemclass(name,list)

           recyclerViewItems.add(index,itemToAdd)
       }
   }
0

There are 0 best solutions below