title: Android : Acces parent fragment function from child fragment
body: <p>I have a <em><strong>Parent Fragment</strong></em> in an <em><strong>activity</strong></em> and have a <em><strong>Child Fragment</strong></em> in <em><strong>Parent Fragment</strong></em>. The NavGraphs of the two Fragments are <em><strong>different</strong></em>. I want to access the function in the <em><strong>Parent Fragment</strong></em> from the <em><strong>Child Fragment</strong></em>, but the application crashes. How can I do it?</p>
  <p><strong>Child Fragment:</strong></p>
  <pre><code>class ProfilinMenu : Fragment(){
  
  private var _binding : FragmentProfilinMenuBinding? = null
  private val profilinmenubinding get() =  _binding!!
  
  override fun onCreate(savedInstanceState: Bundle?) {
  
      super.onCreate(savedInstanceState)
  
  }
  
  override fun onCreateView(
      inflater: LayoutInflater, container: ViewGroup?,savedInstanceState: Bundle?): View {
      _binding = FragmentProfilinMenuBinding.inflate(inflater,container,false)
  
  
      (parentFragment as Parent).changeName() // this is for access parent
  
  
      return profilinmenubinding.root
  }}
  </code></pre>
  <p><strong>Parent Fragment:</strong></p>
  <pre><code>public class Parent : Fragment() {
  
  private var _binding : FragmentParentBinding? = null
  private val parentBinding get() = _binding!!
  private var instance: Parent? = null
  
  
  override fun onCreateView(
      inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
  
      _binding = FragmentParentBinding.inflate(inflater, container, false)
      val view = parentBinding.root
  
    
      return view
  }
  
  public fun changeName(){
      parentBinding.profilinIsmin.text = &quot;Merhaba&quot;
  }
  </code></pre>