简体   繁体   English

如何将(日期)等数据从活动发送到底部工作表对话框片段?

[英]how to send data like (Date) from activity to bottom sheet dialog fragment?

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图片: https://i.stack.imgur.com/8L8E0.png

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.在 function 你打开对话框,你可以传递任何你需要的数据。 here is an example to what you can do:这是您可以执行的操作的示例:

in your activity class:在您的活动 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:并在底部工作表对话框 class 中创建新实例 function,如下所示:

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:在底部工作表对话框 class 的onViewCreated方法中,您将获得在捆绑包中发送的数据,如下所示:

  item = arguments?.getParcelable(KEY_OPEN_DIALOG)

you can use item instance in whatever you want in your bottom sheet fragment您可以在底部工作表片段中随意使用item实例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM