title: Get current fragment displayed in FragmentContainerView from MainActivity
body: <p>Im using Navigation Component which navigates between fragments using <code>findNavController().navigate()</code>. I want to retrieve the currently displayed fragment in <code>FragmentContainerView</code> from <code>MainActivity</code> as I want to modify the &quot;Edit&quot; button <code>setOnClickListener</code> function to perform &quot;Save&quot; function (I already know how to change the text from Edit to Save) where it checks currently displayed fragment and change the <code>setOnClickListener</code> function accordingly. So in that particular fragment, it will perform &quot;Save&quot; function. But how do I get the currently displayed fragment from <code>MainActivity</code>?</p>
  <p>I saw alot other solution but they are all using <code>FragmentTransaction</code> or they just show the code which get the current Fragment but they didn't show in which part of <code>MainActivity</code> will initiate the code which gets the current Fragment. Any help? Im using Kotlin.</p>
  <p><a href="https://i.stack.imgur.com/H93tG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/H93tG.png" alt="enter image description here" /></a></p>