安卓:将参数传递给一个标签 [英] Android : passing parameters to a tab
问题描述
在我的Android应用程序,我用下面的code创建标签:
In my Android app, I use the following code to create tabs :
mTabHost = (FragmentTabHost)findViewById(android.R.id.tabhost);
mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
mTabHost.addTab(mTabHost.newTabSpec("simple").setIndicator("Simple"),
MyFragment.class, null);
在 addTab
的方法,第三个参数是一个Bundle对象,是空
。我可以用这个第三个参数的参数传递给我的片段?
In the addTab
method, the third parameter is a Bundle object and is null
. Could I use this third parameter to pass parameters to my fragment ?
Android的API文档为空 addTab
并不会记录此参数。
The android API documentation is empty for addTab
and does not document this parameter.
推荐答案
答案是肯定的。要传递这个参数捆绑
稍后设为您的片段参数
,可与<一个访问href="http://developer.android.com/reference/android/app/Fragment.html#getArguments%28%29">getArguments从该片段内。
The answer is yes. the parameters you are passing in this Bundle
are later set as your fragment arguments
and can be accessed with getArguments from inside the fragment.
在code,使得它发生在FragmentTabHost是:
The code that makes it happen in the FragmentTabHost is :
newTab.fragment = Fragment.instantiate(mContext,
newTab.clss.getName(), newTab.args);
这篇关于安卓:将参数传递给一个标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!