我正在学习android中的导航组件。 java 中 fragment 之间通信的 val bundle = bundleOf(..) 等价于什么?
最佳答案
这里有一个很好的引用:https://developer.android.com/training/basics/fragments/communicating
总而言之,您可以实例化 bundle 并将其发送到 fragment ,如下所示:
// 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);
此外,为了进行通信, fragment 可以调用父级中的回调,在 fragment 中定义接口(interface)并在父级中实现它。
关于java - 对于java中 fragment 之间的通信, val bundle = bundleOf(..) 相当于什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59957795/