Search code examples
androidkotlinandroid-recyclerviewandroid-listadapter

Get item from new RecyclerView ListAdapter


I updated the adapter for RecyclerViev to the new ListAdapter, but now I don’t understand how to get the clicked object because the adapter no longer has a list of objects. Previously, I used my custom ClickListener interface, which passed to the adapter constructor and next to the viewHolder, through which I received the View and the position of the clicked element

interface RecyclerClickListener {

    fun onClick(view: View, position: Int)

    fun onLongClick(view: View, position: Int)

}

Solution

  • You can use ListAdapter.getItem(position) and pass in the clicked position as an integer.