2

I am using from AppCompatDialogFragment in my DaggerFragment but when run my app get bellow error:

java.lang.IllegalStateException: Fragment CourseTypeListDialogFragment{ab0b7f3 (3d65d8c0-5c75-4b92-8002-1852a8aa58b7) } declared target fragment CoursesFragment{e2a5105 (e277e6f4-7e61-4114-8eb4-d0143a07ac0c) id=0x7f0800cc} that does not belong to this FragmentManager!

I opened it like bellow:

@OnClick(R.id.btnCourseType)
fun btnCourseTypeClick(){
    val fm = activity!!.supportFragmentManager
    val courseTypeListDialogFragment =
        CourseTypeListDialogFragment()
    courseTypeListDialogFragment.setCancelable(false)
    courseTypeListDialogFragment.setStyle(
        DialogFragment.STYLE_NO_TITLE,
        0
    )
    courseTypeListDialogFragment.setTargetFragment(this@CoursesFragment, 1)
    courseTypeListDialogFragment.show(fm, "")

}
PEDY
  • 169
  • 1
  • 11
  • possible duplicate of: https://stackoverflow.com/questions/47045788/fragment-declared-target-fragment-that-does-not-belong-to-this-fragmentmanager/ – some user Feb 05 '20 at 08:16

2 Answers2

0

You did not add the fragment to the fragment manager

fm.beginTransaction().replace(R.id.someFrame, courseTypeListDialogFragment).commitAllowingStateLoss()

only then you'll be able to use show(), hide() on this fragment

Lena Bru
  • 13,521
  • 11
  • 61
  • 126
0

I removed courseTypeListDialogFragment.setTargetFragment(this@CoursesFragment, 1) and good work now.

PEDY
  • 169
  • 1
  • 11