在java中,对于片段之间的通信,val bundle = bundleOf(.)等价于什么?



我正在学习安卓中的导航组件。在java中,对于片段之间的通信,val bundle = bundleOf(..(的等价物是什么?

这里有一个很好的参考:https://developer.android.com/training/basics/fragments/communicating

作为总结,您可以实例化捆绑包并将其发送到片段,如下所示:

// Create fragment and give it an argument for the selected article
ArticleFragment newFragment = new ArticleFragment();
Bundle args = new Bundle();
args.putInt(ArticleFragment.ARG_POSITION, position);
newFragment.setArguments(args);

同样对于通信,片段可以在父级中调用回调,在片段中定义接口并在父级中实现它。

最新更新