Im currently working on an app, which has a BottomSheetDialog
as navigation menu. This menu, is called by the Toolbar Navigation Item.
When calling the BottomSheetDialog, it shows up, and clicking on an item of the list creates the related activity, which is expected. However, when i close the newly opened activity the BottomSheetDialog shows up again, which is not the intended behaviour.
Are there any ways to prevent the BottomSheetFragment to show up?
I tried using .also
after the creation of the Intent, but there are no function dedicated to hide or close the Dialog
Here is the BottomSheetFragment code:
class frgBottomSheetDrawer : BottomSheetDialogFragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
super.onCreateView(inflater, container, savedInstanceState)
return inflater.inflate(R.layout.fragment_bottomsheet, container, false)
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
navDrawer.setNavigationItemSelectedListener { menuItem ->
when (menuItem!!.itemId) {
R.id.ndListFolder -> this.startActivity(Intent(activity, ndActFolder::class.java))
R.id.ndListSettings -> this.startActivity(Intent(activity, ndActSettings::class.java))
R.id.ndListAbout -> this.startActivity(Intent(activity, actAbout::class.java))
}
true
}
}
}
To close the bottomSheet Dialog after an Item Click , try the following
navDrawer.setNavigationItemSelectedListener { menuItem ->
when (menuItem!!.itemId) {
R.id.ndListFolder -> this.startActivity(Intent(activity,
ndActFolder::class.java))
dismiss() // add this whenever you want to close the bottomSheet
}
true
}
So you simply need to add this method dismiss()