片段和onCreate()中的setArguments() [英] setArguments() in Fragment and onCreate()

查看:83
本文介绍了片段和onCreate()中的setArguments()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我创建一个新的 Fragment ,然后为其设置参数,我可以依靠那些始终在 onCreate()中可用的参数>片段?如果是,他们将如何做?如果不是,我该如何沟通,如果他们不希望我们编写新的构造函数?

If I create a new Fragment and then I set arguments to it can I rely on those arguments always being available for me in the onCreate() of the Fragment? If yes, how do they do it? If not how I'am I supposed to communicate if they don't want us to write new constructors?

推荐答案

是的,您的参数在onCreate方法中可用.请检查此响应,以了解如何将参数传递给片段:如何将一些数据传输到另一个片段?

Yes, your arguments are avaialble in onCreate method. Please check it out this response in order to see how to pass arguments to fragments: How to transfer some data to another Fragment?

与片段通信的另一种方法是通过您的活动正在实现的接口,然后在onAttach方法中将其作为对片段的引用进行传递.更多信息: https://developer.android.com/training/basics/fragments/communication

Another way to communicate with the fragment is via a interface that your activity is implementing and you pass it as a reference to your fragment, in onAttach method. More info: https://developer.android.com/training/basics/fragments/communicating

两个片段之间的基本通信

这篇关于片段和onCreate()中的setArguments()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆