title: Android | Kotlin: How to make RecyclerView itemClick from Firebase Cloud Firestore?
body: <p>I want to make my RecyclerView item clickable, and after that show in DetailsActivity. I have made my code like this to show Toast and Log, but no data is showing. Is there something wrong with my code? Or is something missing? I have searched Google and YouTube a lot that should use Firestore Adapter. Is that so? If yes, I don't know how to use this Firestore Adapter.</p>
  <p>This is code for <strong>OutletAdapter.kt</strong></p>
  <pre><code>class OutletAdapter(private val context: Context, private val outletList: MutableList&lt;Outlet&gt;) : RecyclerView.Adapter&lt;OutletAdapter.OutletViewHolder&gt;() {
  
      private lateinit var itemOutletBuyerBinding: ItemOutletBuyerBinding
  
      private var onItemClickListener: OnItemClickListener? = null
  
      override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): OutletViewHolder {
          itemOutletBuyerBinding = ItemOutletBuyerBinding.inflate(LayoutInflater.from(parent.context), parent, false)
  
          return OutletViewHolder(itemOutletBuyerBinding)
      }
  
      override fun onBindViewHolder(holder: OutletViewHolder, position: Int) {
          holder.bind(outletList[position])
      }
  
      override fun getItemCount(): Int {
          return outletList.size
      }
  
      fun setOnItemClickListener(onItemClickListener: OnItemClickListener?) {
          this.onItemClickListener = onItemClickListener
      }
  
      inner class OutletViewHolder(private val itemOutletBuyerBinding: ItemOutletBuyerBinding) : RecyclerView.ViewHolder(itemOutletBuyerBinding.root) {
  
          fun bind(outlet: Outlet) {
              with(itemOutletBuyerBinding) {
  
                      ... -&gt; View Binding
  
                  }
              }
  
              itemView.setOnClickListener {
                  onItemClickListener?.onItemClicked(outlet)
              }
          }
  
      }
  
      interface OnItemClickListener {
          fun onItemClicked(data: Outlet)
      }
  
  }
  </code></pre>
  <p>This is code for <strong>Fragment.kt</strong></p>
  <pre><code>rvExploreBuyerOutlet.apply {
      layoutManager = GridLayoutManager(requireActivity(), 2)
      setHasFixedSize(true)
  
      firebaseFirestore.collection(&quot;outlets&quot;).get().apply {
          addOnSuccessListener { querySnapshot -&gt;
                      
              ...
  
              querySnapshot.toObjects(Outlet::class.java).also { outletData -&gt;
                  outletList.apply {
                      for (i in 0 until outletData.size / 2) {
                          add(outletData[i])
                          add(outletData[i + outletData.size / 2])
                      }
  
                      for (i in 0 until size / 2) {
                          when {
                              i % 2 == 0 -&gt; {
                                  val temp = this[i]
  
                                  this[i] = this[size - 2 - i]
                                  this[size - 2 - i] = temp
                              }
                          }
                      }
  
                      for (document in this) {
                          outletAdapter = OutletAdapter(requireActivity(), this as ArrayList&lt;Outlet&gt;)
                      }
                  }
              }
  
              adapter = outletAdapter
  
              outletAdapter.setOnItemClickListener(object : OutletAdapter.OnItemClickListener {
                  override fun onItemClicked(data: Outlet) {
                      Toast.makeText(requireActivity(), &quot;Item ${data.outletNumber}&quot;, Toast.LENGTH_SHORT).show()
                      Log.d(&quot;itemClicked&quot;, data.toString())
                  }
              })
  
              adapter?.notifyDataSetChanged()
          }
      }
  }
  </code></pre>