title: How to implement an alert dialog inside adapter in RecyclerView adater list Kotlin?
body: <p>what I am trying to do is implement an alert dialog on an adapter item. I managed to make it on java but I am trying to make it in kotlin. </p>
  
  <p>This is the main class where I start the adapter.</p>
  
  <pre><code>fun buildDetailsAdapter() {
          //recicler view saleDetails
          val saleDetail = SaleDetail()
          val saleDetailList = saleDetail.getSaleDetailsbyIdSaleHeader(idSaleHeader)
          Log.i(TAG, "buildProductsAdapter " + saleDetailList.size)
  
          val saleDetailAdapter = PreProductDevolutionKAdapter(saleDetailList, context)
  
              saleDetailAdapter.setOnClickListener(View.OnClickListener { v -&gt;
                  val builder = AlertDialog.Builder(this)
                  builder.setTitle("Androidly Alert")
                  builder.setMessage("We have a message")
                  //builder.setPositiveButton("OK", DialogInterface.OnClickListener(function = x))
  
                  builder.setPositiveButton(android.R.string.yes) { dialog, which -&gt;
                      Toast.makeText(applicationContext,
                              android.R.string.yes, Toast.LENGTH_SHORT).show()
                  }
  
                  builder.setNegativeButton(android.R.string.no) { dialog, which -&gt;
                      Toast.makeText(applicationContext,
                              android.R.string.no, Toast.LENGTH_SHORT).show()
                  }
  
                  builder.setNeutralButton("Maybe") { dialog, which -&gt;
                      Toast.makeText(applicationContext,
                              "Maybe", Toast.LENGTH_SHORT).show()
                  }
                  builder.show()
              })
  
          rcvProductDevolution.adapter = saleDetailAdapter
      }
  </code></pre>
  
  <p>This is the adapter class</p>
  
  <pre><code>class PreProductDevolutionKAdapter(val items : List&lt;SaleDetail&gt;, val context: Context) : RecyclerView.Adapter&lt;ViewHolder&gt;() {
  
      private var listener: View.OnClickListener? = null
  
  
      override fun onCreateViewHolder(parent: ViewGroup, p1: Int): ViewHolder {
          return ViewHolder(LayoutInflater.from(context).inflate(R.layout.adapter_pre_product_devolution_k, parent, false))
      }
  
      override fun onBindViewHolder(holder: ViewHolder, position: Int) {
          holder.txtIdProductSaleDetailsAdapter.text = items[position].idProduct.toString()
          holder.txtQuantitySaleDetailsAdapter.text = items[position].quantity.toString()
          holder.txtQuantityToReturnAvailable.text = items[position].quantityReturn.toString()
          holder.txtUnitSaleDetailProductValue.text = items[position].unitValue.toString()
          holder.txtValuetotSaleDetailsAdapter.text = items[position].totValue.toString()
      }
  
      // Gets the number of animals in the list
      override fun getItemCount(): Int {
          return items.size
      }
  
      fun setOnClickListener(listener: View.OnClickListener) {
          this.listener = listener
      }
  
  
  }
  
  class ViewHolder (view: View) : RecyclerView.ViewHolder(view) {
      // Holds the TextView that will add each animal to
      val txtIdProductSaleDetailsAdapter: TextView = view.txtIdProductSaleDetailsAdapter
      val txtQuantitySaleDetailsAdapter: TextView = view.txtQuantitySaleDetailsAdapter
      val txtQuantityToReturnAvailable: TextView = view.txtQuantityToReturnAvailable
      val txtUnitSaleDetailProductValue: TextView = view.txtUnitSaleDetailProductValue
      val txtValuetotSaleDetailsAdapter : TextView= view.txtValuetotSaleDetailsAdapter
  }
  </code></pre>
  
  <p>The adapter view is inflated fine and the information is display as expected, but when I click on an item nothing happens.</p>
  
  <p>Any help or suggestions would be nice. thanks</p>