'How to show dialogFragment in Adapter onBindViewHolder using findNavController?

i have a problem. i want to show my EditFragment when item clicked, but it keep going to my EditFragment instead of showing Dialog

this is the code

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
    val type = list[position]
    holder.binding.tvTitle.text = type.title
    holder.binding.tvIsiNotes.text = type.content

    holder.itemView.setOnClickListener{
        holder.itemView.findNavController().navigate(HomeFragmentDirections.actionHomeFragmentToEditFragment(type))
    }


Solution 1:[1]

You should pass your click event to your fragment/activity

class YourAdapter(
  val list: List<Foo>,
  val listener: OnItemClickListener){

  interface OnItemClickListener {
     fun onItemClick(type:Foo)
  {

  override fun onBindViewHolder(holder: ViewHolder, position: Int) {
    val type = list[position]
    holder.binding.tvTitle.text = type.title
    holder.binding.tvIsiNotes.text = type.content

    holder.itemView.setOnClickListener{
       listener.onItemClick(type)
    }
}

In fragment/activity

adapter = YourAdaper(yourList, object : YourAdapter.OnItemClickListener {
   override fun onItemClick (type){ findNavController().navigate(HomeFragmentDirections.actionHomeFragmentToEditFragment(type))
   }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Muhammad Rio