Meltix
Meltix

Reputation: 499

android - How to show BottomSheetDialog from a fragment?

Im working on an app which has a Fragment containing the widget Toolbar and a Recyclerview. The fragment is a CoordinatorLayout.

I need to call my BottomSheetDrawer on Navigation button click. Since my Toolbar is inside a fragment, i need to show the BottomSheetDrawer trough there.

I tried implementing the function the same way as Activity, however it doesnt work, because supportFragmentManager is flagged as an unresolved reference.

What's the correct way to show a BottomSheetFragment from a fragment?

Fragment.kt

class FragmentTrack : Fragment() {
    
    ...

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        topToolbar.setNavigationOnClickListener {
            val dialog = FragmentBottomSheetDrawer()
            dialog.show(supportFragmentManager, dialog.tag)

        }
    }

    ...
}

Upvotes: 0

Views: 989

Answers (1)

ianhanniballake
ianhanniballake

Reputation: 199825

The equivalent to supportFragmentManager in a Fragment is childFragmentManager. That is the correct FragmentManager to use for any kind of DialogFragment.

Upvotes: 3

Related Questions