Instead of invoking a presenter inside your adapter, I would prefer to make a click interface to invoke it from the view, since you will instantiate this adapter in your view, it would be nice to save the MVP template by clicking the elements inside your view, and not in the adapter itself.
This example is in Kotlin, but I'm sure you will understand this.
First, just create a simple interface to trigger a click event when the user clicks on any item in your list.
class EquipmentAdapter(private val context: Context,private var equipmentList:ArrayList<Equipment>,itemListener:RecyclerViewClickListener): RecyclerView.Adapter<EquipmentAdapter.EquipmentViewHolder>() { interface RecyclerViewClickListener { fun recyclerViewListClicked(v: View?, position: Int) } companion object{ var itemClickListener: RecyclerViewClickListener? = null var equipmentSearchList:ArrayList<Equipment>? = null } init { equipmentSearchList = equipmentList itemClickListener = itemListener }
Then inside your ViewHolder you must call this interface to handle the click
inner class EquipmentViewHolder(itemView: View): RecyclerView.ViewHolder(itemView), View.OnClickListener { val equipmentName:TextView = itemView.txt_equipmentname init { itemView.setOnClickListener(this) } override fun onClick(v: View?) { itemClickListener?.recyclerViewListClicked(v, adapterPosition) } }
Finally, just implement the click interface in the view that you call the adapter, and then simply control the speaker interactions inside the adapter instead.
class EquipmentActivity : BaseActivity(), EquipmentContract.EquipmentView, EquipmentAdapter.RecyclerViewClickListener ...
And implement the click method
override fun recyclerViewListClicked(v: View?, position: Int) { presenter.onItemInteraction(position) }
By doing this, you check that the clicks on the elements in the list are made from the view itself, and not from the adapter, here you can interact with the speaker as always, as well as do more things that will keep your project clean,