title: How to implement onClickListener for CardView inside RecyclerView using Firebase data?
body: <p>I am creating an e-commerce application which displays the products with CardView inside RecyclerView. I am hosting the data in Firebase and I did the coding to display the data from Firebase into the CardView. Now, I want to display the details of the products in a separate activity. When a product Cardview is clicked, I want to launch an activity which displays the details of the respective product from Firebase.</p>
  <p>I watched a few tutorials on YouTube and tried it, but those methods didn't work. I am using Kotlin. Below is my RecyclerView adapter and the class file of the RecyclerView activity.</p>
  <p>ProductView Adapter</p>
  <pre><code>class ProductAdapter(private var productlist:MutableList&lt;Product&gt;): 
      RecyclerView.Adapter&lt;ProductAdapter.ProductViewHolder&gt;() {
      override fun onCreateViewHolder(
          parent: ViewGroup,
          viewType: Int
      ): ProductViewHolder {
  
          val layoutView:View = LayoutInflater.from(parent.context).inflate(R.layout.itemcard,parent,false)
          return ProductViewHolder(layoutView)
  
      }
  
      override fun onBindViewHolder(holder: ProductViewHolder, position: Int) {
  
          Picasso.get().load(productlist[position].prdimg).into(holder.prdimg)
          holder.prdname.text = productlist[position].prdname
          holder.prdprice.text = productlist[position].prdprice
  
  
      }
  
      override fun getItemCount(): Int {
          return productlist.size;
      }
  
      inner class ProductViewHolder(view: View): RecyclerView.ViewHolder(view){
  
          var prdimg: ImageView = view.findViewById(R.id.prdimg)
          var prdname: TextView = view.findViewById(R.id.prdname)
          var prdprice: TextView = view.findViewById(R.id.prdprice)
  
      }  
  </code></pre>
  <p>Here is my Kotlin class</p>
  <pre><code>private const val ARG_PARAM1 = &quot;param1&quot;
  private const val ARG_PARAM2 = &quot;param2&quot;
  
  class storekotlin : Fragment() {
  
      private var param1: String? = null
      private var param2: String? = null
  
      var recyclerView: RecyclerView? = null
  
      var productlist = ArrayList&lt;Product&gt;()
      private var database: FirebaseDatabase? = null
      private var reference: DatabaseReference? = null
  
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          arguments?.let {
              param1 = it.getString(ARG_PARAM1)
              param2 = it.getString(ARG_PARAM2)
          }
      }
  
      override fun onCreateView(
          inflater: LayoutInflater, container: ViewGroup?,
          savedInstanceState: Bundle?
      ): View? {
          var view =  inflater.inflate(R.layout.fragment_storekotlin, container, false)
  
          database = FirebaseDatabase.getInstance()
          reference = database?.getReference(&quot;Products&quot;)
  
          val FirebaseListener = object: ValueEventListener {
              override fun onDataChange(p0: DataSnapshot) {
  
                  val child = p0.children
                  child.forEach{
  
                      var products = Product(it.child(&quot;img&quot;).value.toString(), 
       it.child(&quot;name&quot;).value.toString(), it.child(&quot;price&quot;).value.toString())
  
                      productlist.add(products)
  
                  }
  
                  val adapter = ProductAdapter(productlist)
                  recyclerView?.adapter = adapter
              }
  
              override fun onCancelled(p0: DatabaseError) {
              }
          }
          reference?.addValueEventListener(FirebaseListener)
  
          recyclerView = view.findViewById(R.id.recyclerview)
          recyclerView?.setHasFixedSize(true)
          recyclerView?.layoutManager = GridLayoutManager(activity, 1, 
      GridLayoutManager.VERTICAL, false)
  
          //productlist.add(product1)
          //productlist.add(product2)
          //productlist.add(product3)
          //productlist.add(product4)
  
          val defuserimg: ImageView = view.findViewById(R.id.defuserimg)
          val defuser: TextView = view.findViewById(R.id.defuser)
          val info:  ImageView = view.findViewById(R.id.info)
          val search: EditText = view.findViewById(R.id.search)
  
          defuserimg.setOnClickListener {
              val intent = Intent(activity, signin_page::class.java)
              startActivity(intent)
          }
  
          defuser.setOnClickListener {
              val intent = Intent(activity, signin_page::class.java)
              startActivity(intent)
          }
  
          info.setOnClickListener {
              val intent = Intent(activity, aboutpage::class.java)
              startActivity(intent)
          }
  
          return view
      }
  
  
      companion object {
  
          @JvmStatic
          fun newInstance(param1: String, param2: String) =
              storekotlin().apply {
                  arguments = Bundle().apply {
                      putString(ARG_PARAM1, param1)
                      putString(ARG_PARAM2, param2)
                  }
              }
      }
  </code></pre>