如何将(日期)之类的数据从 activity 发送到底部 sheet 对话框片段?
how to send data like (Date) from activity to bottom sheet dialog fragment?
大家好,我想将(日期变量)从 activity 发送到底部 sheet 片段,我该怎么做?
图片:https://i.stack.imgur.com/8L8E0.png
您可以通过在打开底部 sheet 对话框时传递数据来实现。
在你打开对话框的函数中,你可以传递任何你需要的数据。
这是您可以执行的操作的示例:
在你的 activity class:
val openDialogToEdit = NewDialogFragment().newInstance(item)
openDialogToEdit.show(supportFragmentManager, TAG)
并在底部 sheet 对话框中 class 创建新的实例函数,如下所示:
fun newInstance(
item: Item?
): NewDialogFragment {
val args = Bundle()
args.putParcelable(KEY_OPEN_DIALOG, item)
val fragment = NewDialogFragment()
fragment.arguments = args
return fragment
}
并且在底部 sheet 对话框 class 的 onViewCreated
方法中,您将获得在捆绑包中发送的数据,类似于:
item = arguments?.getParcelable(KEY_OPEN_DIALOG)
您可以在底部 sheet 片段
中的任何地方使用 item
实例
大家好,我想将(日期变量)从 activity 发送到底部 sheet 片段,我该怎么做? 图片:https://i.stack.imgur.com/8L8E0.png
您可以通过在打开底部 sheet 对话框时传递数据来实现。
在你打开对话框的函数中,你可以传递任何你需要的数据。 这是您可以执行的操作的示例:
在你的 activity class:
val openDialogToEdit = NewDialogFragment().newInstance(item)
openDialogToEdit.show(supportFragmentManager, TAG)
并在底部 sheet 对话框中 class 创建新的实例函数,如下所示:
fun newInstance(
item: Item?
): NewDialogFragment {
val args = Bundle()
args.putParcelable(KEY_OPEN_DIALOG, item)
val fragment = NewDialogFragment()
fragment.arguments = args
return fragment
}
并且在底部 sheet 对话框 class 的 onViewCreated
方法中,您将获得在捆绑包中发送的数据,类似于:
item = arguments?.getParcelable(KEY_OPEN_DIALOG)
您可以在底部 sheet 片段
中的任何地方使用item
实例