title: clicklistener not working in recyclerview
body: <p>Im following this link answer--&gt; <a href="https://stackoverflow.com/a/32323801/12553303">https://stackoverflow.com/a/32323801/12553303</a>  ...on click of item im getting an error of invalid product id...but how do i get id from adapter to activity??????? i have used interface for click listener...
  need help in here --&gt; <code>RetrofitClient.instance.deletecart(token, dataList?.get(position)?.product_id.toString())</code></p>
  <p>on debuuging this line</p>
  <p><a href="https://i.stack.imgur.com/HUNOj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HUNOj.png" alt="enter image description here" /></a></p>
  <p>following is my code :--</p>
  <pre><code>class CartAdapter(private val context: Context, private val dataList: MutableList&lt;DataCart?&gt;?) :
  RecyclerSwipeAdapter&lt;CartAdapter.CustomViewHolder&gt;() , AdapterView.OnItemSelectedListener{ //added RecyclerSwipeAdapter and override
  
  var progressDialog: ProgressDialog? = null
  
  private var itemClick: OnItemClick? = null
  
  inner class CustomViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView){
  
      val mView: View
    val swipelayout:SwipeLayout
      val productiamge: ImageView
      val productname: TextView
      val productcategory: TextView
      val productprice: TextView
      val tvDelete:TextView
      val spin:Spinner
      init {
          mView = itemView
      productiamge= mView.findViewById(R.id.imagecart)
         productname= mView.findViewById(R.id.imagenamecart)
          productcategory= mView.findViewById(R.id.imagecategory)
  
       productprice =mView.findViewById(R.id.price)
          swipelayout=mView.findViewById(R.id.swipe)
          tvDelete=mView.findViewById(R.id.tvDelete)
           spin = mView.findViewById(R.id.spinner) as Spinner
          tvDelete.setClickable(true);
          tvDelete.setOnClickListener {
              if (itemClick != null) {
                  itemClick!!.onItemClicked(getPosition());
              }
          }
  
  
      }
  
  
  }
  
  override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CustomViewHolder {
      val layoutInflater = LayoutInflater.from(parent.context)
      val view: View = layoutInflater.inflate(R.layout.addtocart_item, parent, false)
  
      return CustomViewHolder(view)
  }
  
  override fun getSwipeLayoutResourceId(position: Int): Int {
      return R.id.swipe;
  
  }
  
  override fun onBindViewHolder(holder: CustomViewHolder, position: Int) {
    val  progressDialog :ProgressDialog= ProgressDialog(context);
      holder.productname.text = dataList?.get(position)?.product?.name ?: null
      holder.productcategory.text = &quot;(&quot; +dataList?.get(position)?.product?.product_category +&quot;)&quot;
  
      holder.productprice.text = dataList?.get(position)?.product?.cost.toString()
  
      Glide.with(context).load(dataList?.get(position)?.product?.product_images)
          .into(holder.productiamge)
  
      holder.swipelayout.setShowMode(SwipeLayout.ShowMode.PullOut)
      Log.e(&quot;checkidd&quot;, dataList?.get(position)?.product?.id.toString())
      // Drag From Right
  
      // Drag From Right
      holder.swipelayout.addDrag(
          SwipeLayout.DragEdge.Right,
          holder.swipelayout.findViewById(R.id.bottom_wrapper)
      )
  
  
  
      //im not able to get this id in activity
       val id =dataList?.get(position)?.product?.id
  
      holder.swipelayout.addSwipeListener(object : SwipeListener {
          override fun onClose(layout: SwipeLayout) {
              //when the SurfaceView totally cover the BottomView.
          }
  
          override fun onUpdate(layout: SwipeLayout, leftOffset: Int, topOffset: Int) {
              //you are swiping.
          }
  
          override fun onStartOpen(layout: SwipeLayout) {}
          override fun onOpen(layout: SwipeLayout) {
          }
  
          override fun onStartClose(layout: SwipeLayout) {}
          override fun onHandRelease(
              layout: SwipeLayout,
              xvel: Float,
              yvel: Float
          ) {
          }
      })
  
  
      holder.swipelayout.getSurfaceView()
          .setOnClickListener(View.OnClickListener {
          })
  
  
      holder.tvDelete.setOnClickListener(View.OnClickListener { view -&gt;
          mItemManger.removeShownLayouts(holder.swipelayout)
          notifyItemChanged(position)
          notifyItemRemoved(position)
          dataList?.removeAt(position)
          notifyItemRangeChanged(position, dataList?.size!!)
          mItemManger.closeAllItems()
                  itemClick?.onItemClicked(position)
  
      })
      mItemManger.bindView(holder.itemView, position)
  
  
  }
      override fun getItemCount() = dataList?.size ?: 0
  
  fun progress()
  {
      progressDialog?.dismiss()
      val intent =
          Intent(context.applicationContext, AddToCart::class.java)
      intent.flags =
          Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_MULTIPLE_TASK
      context.applicationContext.startActivity(intent)
      (context as Activity?)!!.overridePendingTransition(0, 0)
  
  
  
  }
  
  
  
  override fun onNothingSelected(p0: AdapterView&lt;*&gt;?) {
      TODO(&quot;Not yet implemented&quot;)
  }
  
  override fun onItemSelected(p0: AdapterView&lt;*&gt;?, p1: View?, p2: Int, p3: Long) {
  
  }
  
  fun getItemClick(): OnItemClick? {
      return itemClick
  }
  
  fun setItemClick(itemClick: OnItemClick?) {
      this.itemClick = itemClick
  }
  </code></pre>
  <p>}</p>
  <p>activity:----------</p>
  <pre><code>    class AddToCart:BaseClassActivity(), OnItemClick{
     val dataList: MutableList&lt;DataCart?&gt;? = null
  
  override fun onCreate(savedInstanceState: Bundle?) {
      super.onCreate(savedInstanceState)
      setContentView(R.layout.add_to_cart)
      getWindow().setExitTransition(null)
      getWindow().setEnterTransition(null)
      var mActionBarToolbar = findViewById&lt;androidx.appcompat.widget.Toolbar&gt;(R.id.toolbartable);
      setSupportActionBar(mActionBarToolbar);
      // add back arrow to toolbar
    setEnabledTitle()
  
      mActionBarToolbar.setNavigationOnClickListener(View.OnClickListener {
          onBackPressed()
      })
      placeorder.setOnClickListener {
          val intent:Intent=Intent(applicationContext, AddressActivity::class.java)
          startActivity(intent)
      }
        loadCart()
  }
  
    fun loadCart(){
  
    val model = ViewModelProvider(this)[CartViewModel::class.java]
  
    model.CartList?.observe(this, object : Observer&lt;CartResponse&gt; {
        override fun onChanged(t: CartResponse?) {
  
            generateDataList(t?.data?.toMutableList())
            totalamount.setText(t?.total.toString())
        }
    })
    }
  
  fun generateDataList(dataList: MutableList&lt;DataCart?&gt;?) {
      val recyclerView=findViewById&lt;RecyclerView&gt;(R.id.addtocartrecyleview) as? RecyclerView
      val linear:LinearLayoutManager=
          LinearLayoutManager(applicationContext, LinearLayoutManager.VERTICAL, false)
      recyclerView?.layoutManager=linear
      val adapter = CartAdapter(this@AddToCart, dataList)
      recyclerView?.adapter=adapter
      recyclerView?.addItemDecoration(DividerItemDecorator(resources.getDrawable(R.drawable.divider)))
     // recyclerView?.setHasFixedSize(true)
      adapter.setItemClick(this);
  
      adapter.notifyDataSetChanged()
      if (dataList?.isEmpty() ?: true) {
          recyclerView?.setVisibility(View.GONE)
          totalamount.setVisibility(View.GONE)
          fl_footer.setVisibility(View.GONE)
          placeorder.setVisibility(View.GONE)
          emptytext.setVisibility(View.VISIBLE)
      } else {
          recyclerView?.setVisibility(View.VISIBLE)
          totalamount.setVisibility(View.VISIBLE)
          fl_footer.setVisibility(View.VISIBLE)
          placeorder.setVisibility(View.VISIBLE)
          emptytext.setVisibility(View.GONE)
  
  
      }
    recyclerView?.addOnScrollListener(object :
        RecyclerView.OnScrollListener() {
        override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
            super.onScrollStateChanged(recyclerView, newState)
            Log.e(&quot;RecyclerView&quot;, &quot;onScrollStateChanged&quot;)
        }
  
        override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
            super.onScrolled(recyclerView, dx, dy)
        }
    })
  }
  override fun onBackPressed() {
      super.onBackPressed()
      val intent = Intent(this, HomeActivity::class.java)
   startActivity(intent)
  }
  override fun onOptionsItemSelected(item: MenuItem): Boolean {
      return when (item.itemId) {
          android.R.id.home -&gt; {
              NavUtils.navigateUpFromSameTask(this)
  
              true
          }
          else -&gt; super.onOptionsItemSelected(item)
      }
  }
  
  override fun onResume() {
      super.onResume()
   loadCart()
  }
  
  
  override fun onItemClicked(position: Int) {
  
      val token: String = SharedPrefManager.getInstance(applicationContext).user.access_token.toString()
      RetrofitClient.instance.deletecart(token, dataList?.get(position)?.product_id.toString())
          .enqueue(object : Callback&lt;DeleteResponse&gt; {
              override fun onFailure(call: Call&lt;DeleteResponse&gt;, t: Throwable) {
  
                  Log.d(&quot;res&quot;, &quot;&quot; + t)
  
  
              }
  
              override fun onResponse(
                  call: Call&lt;DeleteResponse&gt;,
                  response: Response&lt;DeleteResponse&gt;
              ) {
                  var res = response
  
                  if (res.body()?.status == 200) {
                      Toast.makeText(
                          applicationContext,
                          res.body()?.message,
                          Toast.LENGTH_LONG
                      ).show()
  
  
  
                  } else {
                      try {
                          val jObjError =
                              JSONObject(response.errorBody()!!.string())
                          Toast.makeText(
                              applicationContext,
                              jObjError.getString(&quot;message&quot;) + jObjError.getString(&quot;user_msg&quot;),
                              Toast.LENGTH_LONG
                          ).show()
                      } catch (e: Exception) {
                          Toast.makeText(applicationContext, e.message, Toast.LENGTH_LONG).show()
                          Log.e(&quot;errorrr&quot;, e.message)
                      }
                  }
              }
          })
  }
  </code></pre>
  <p>}</p>
  <p>need help thanks</p>