gpt4 book ai didi

java - java中 fragment 之间的通信相当于val bundle = bundleOf(..)?

转载 作者:行者123 更新时间:2023-12-04 21:16:29 24 4
gpt4 key购买 nike

我正在学习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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com