title: Android RecyclerView Navigation in Adapter
body: <p>I am trying to navigate to a fragment within a RecyclerView adapter, the reason being I have a list of items with buttons with different text and on click of each button depending on the text on the button, I want it to navigate to different fragments that correspond to that text. What is the best way to handle this navigation?</p>
  
  <pre><code>     class DummyAdapter(val context: Context, private var DummyList: ArrayList&lt;DummyModel&gt;) :
          RecyclerView.Adapter&lt;DummyAdapter.DummyViewHolder&gt;() {
  
          override fun onCreateViewHolder(parent: ViewGroup, p1: Int): DummyViewHolder {
              val dummyBinding: ListItemDummyBinding = DataBindingUtil.inflate(
                  LayoutInflater.from(parent.context),
                  R.layout.list_item_dummy,
                  parent,
                  false
              )
              return DummyViewHolder(dummyBinding)
          }
  
          override fun getItemCount(): Int {
              return dummyList.size
          }
  
          override fun onBindViewHolder(holder: DummyViewHolder, position: Int) {
              val item = dummyList[position]
              holder.bind(item)
  
              holder.dummyItemBinding.buttonDummy.setOnClickListener {
                  if (holder.dummyItemBinding.buttonDummy.text == "Fragment 1") {
  
                      //The actual Navigation Logic to be added
                  }
              }
              holder.dummyItemBinding.buttonDummy.setOnClickListener {
                  if (holder.dummyItemBinding.buttonDummy.text == "Fragment 2") {
  
                      //The actual Navigation Logic to be added
                  }
  
              }
          }
  
              inner class DummyViewHolder(var dummyItemBinding: ListItemDummyBinding) :
                  RecyclerView.ViewHolder(dummyItemBinding.root) {
                  private lateinit var dummyItem: DummyModel
                  fun bind(dummyItem: DummyModel) {
                      this.dummyItem = dummyItem
                      dummyItemBinding.buttonDummy.text = dummyItem.button_text
                  }
              }
     }
  </code></pre>