https://kotlinlang.org logo
Title
a

Aslam Hossin

05/05/2020, 4:50 AM
Listener registration not working in fragment to Dialog fragment communication. Am I missing anything for registration ?
override fun onAttach(context: Context) {
    AndroidSupportInjection.inject(this)
    super.onAttach(context)
    if (context is Listener) {
      listener = context
    }
  }

  override fun onDetach() {
    super.onDetach()
    listener = null
  }
d

David Eriksson

05/05/2020, 7:50 AM
I don't think that's how you pass a listener to a fragment...
a

Aslam Hossin

05/05/2020, 11:20 AM
I've been solved this issue in this way
override fun onCreate(savedInstanceState: Bundle?) {
  super.onCreate(savedInstanceState)
  listener=
    parentFragment?.childFragmentManager?.primaryNavigationFragment.cast<Listner>()
}

override fun onDestroy() {
  super.onDestroy()
  listener= null
}
d

David Eriksson

05/05/2020, 12:00 PM
That's not how Google recommends either, but it's your app :)
a

Aslam Hossin

05/05/2020, 12:05 PM
Basically I have been tried different ways even you suggested one but no luck. Only the above solutions working perfectly. Thanks for your input. Fragment to DialogFragemnt target set not register at all and that's why I have been implemented this solution.