dead.fish
12/07/2022, 2:22 PMimport android.os.Bundle
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.Fragment
class OuterFragment : Fragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
MyDialogFragment.create(Bundle()).apply {
show(childFragmentManager, "DIALOG")
// ^--- this should be this@OuterFragment.childFragmentManager
}
}
}
class MyDialogFragment : DialogFragment() {
companion object {
fun create(bundle: Bundle): MyDialogFragment =
MyDialogFragment().apply {
arguments = bundle
}
}
}
Any hints how I could make childFragmentManager
yellowish in the IDE?kevin.cianfarini
12/07/2022, 5:58 PMthis
scope changes, but I would argue that you shouldn’t be using .apply
here and instead be using
Fragment.create(...).also { fragment ->
fragment.show(...)
}
dead.fish
12/12/2022, 2:01 PMalso
is the better alternative, but sometimes people do not think about this - I really want a warning however in case of misuse.