hi guys I want to send (Date variable) from activity to bottom sheet fragment how can I do this ? the image : https://i.stack.imgur.com/8L8E0.png
CodePudding user response:
You can make this by passing the data when you open the bottom sheet dialog.
in the function you open the dialog in it, you can pass whatever data you need. here is an example to what you can do:
in your activity class:
val openDialogToEdit = NewDialogFragment().newInstance(item)
openDialogToEdit.show(supportFragmentManager, TAG)
and in the bottom sheet dialog class you create the new instance function something like this:
fun newInstance(
item: Item?
): NewDialogFragment {
val args = Bundle()
args.putParcelable(KEY_OPEN_DIALOG, item)
val fragment = NewDialogFragment()
fragment.arguments = args
return fragment
}
and in the onViewCreated
method in your bottom sheet dialog class, you get the data you send in the bundle something like that:
item = arguments?.getParcelable(KEY_OPEN_DIALOG)
you can use item
instance in whatever you want in your bottom sheet fragment