title: Custom listener for RecyclerView is not detecting clicks
body: <p><a href="https://guides.codepath.com/android/Using-the-RecyclerView#simple-click-handler-within-viewholder" rel="nofollow noreferrer">This</a>
   is the tutorial I am following, under "Attaching Click Handlers using Listeners"</p>
  
  <p>I am trying to implement a custom listener to pass to an adapter. This is to ensure the adapter runs the code in <code>MainActivity</code> when a RecyclerView item is clicked.
  It is done inside <code>adapter.setOnItemClickListener</code></p>
  
  <p>When I click on one of the items in my recyclerview, <code>showAlertDialog()</code> does not run.
  Is it because I have placed my recyclerview in a swiperefreshlayout?</p>
  
  <pre><code>class MainActivity : AppCompatActivity(), MainContract.View {
  
      private lateinit var presenter: MainContract.Presenter
      private lateinit var adapter: MainAdapter
  
      override fun onCreate(savedInstanceState: Bundle?) {
  
          ...
  
          swipe_container.setOnRefreshListener { presenter.refreshPlaceList() }
  
          recyclerViewPlaces.layoutManager = LinearLayoutManager(this)
      }
  
      override fun showFavouritePlaces(favouritePlaces: List&lt;Place&gt;) {
          adapter = MainAdapter(favouritePlaces.toMutableList(), this)
  
          // Anonymous object passed here as listener
          adapter.setOnItemClickListener(object: MainAdapter.OnItemClickListener{
              override fun onItemClick(itemView: View) {
                  showAlertDialog()
              }
          })
  
          recyclerViewPlaces.adapter = adapter
      }
  
      override fun showFavouritePlace(favouritePlace: Place) {
          if (this::adapter.isInitialized) {
              adapter.addFavouritePlace(favouritePlace)
          } else {
              adapter = MainAdapter(mutableListOf(favouritePlace), this)
              recyclerViewPlaces.adapter = adapter
          }
      }
  
      override fun showAlertDialog() {
          val builder = AlertDialog.Builder(this)
  
          builder.setTitle("Delete")
  
          builder.setMessage("Would you like to delete this place?")
  
          builder.setPositiveButton("YES") { dialog, which -&gt;
              Toast.makeText(applicationContext, "Yes selected", Toast.LENGTH_SHORT).show()
          }
  
          builder.setNegativeButton("No") { dialog, which -&gt;
              Toast.makeText(applicationContext, "Nope", Toast.LENGTH_SHORT).show()
          }
  
          val dialog: AlertDialog = builder.create()
  
          dialog.show()
      }
  }
  
  
  class MainAdapter(private val favouritePlaces: MutableList&lt;Place&gt;, private val context: Context)
      : RecyclerView.Adapter&lt;MainAdapter.CustomViewHolder&gt;() {
  
      private lateinit var listener: OnItemClickListener
  
      interface OnItemClickListener {
          fun onItemClick(itemView: View)
      }
  
      fun setOnItemClickListener(listener: OnItemClickListener) {
          this.listener = listener
      }
  
      class CustomViewHolder(val view: View, private val listener: OnItemClickListener)
                                  : RecyclerView.ViewHolder(view), View.OnClickListener {
  
          override fun onClick(v: View?) {
              if (listener != null) {
                  listener.onItemClick(v!!)
              }
          }
      }
  
      override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MainAdapter.CustomViewHolder {
          val placeView = LayoutInflater.from(parent.context)
                  .inflate(R.layout.place_list_item, parent, false)
  
          return MainAdapter.CustomViewHolder(placeView, listener)
      }
  
      override fun onBindViewHolder(holder: MainAdapter.CustomViewHolder, position: Int) {
  
          holder.view.isLongClickable = true
  
          // Setting XML properties
      }
  }
  </code></pre>