我正在尝试在Android中使用带有选项卡的滑动视图,我需要将一些变量传递给选项卡的片段以显示自定义内容,我的问题是我总是将捆绑到0,所以我认为我是从片段容器页面发送附加内容时出错了。这是片段的代码和包含选项卡的主片段页面。
public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page.
// Return a PlaceholderFragment (defined as a static inner class
// below).
prof = getIntent().getIntExtra("prof", 0);
id = getIntent().getIntExtra("id", 0);
bund = new Bundle();
bund.putInt("prof", prof);
bund.putInt("id", id);
switch (position) {
case 0:
// Text fragment activity
FragmentOne fragment = new FragmentOne();
fragment.setArguments(bund);
return fragment;
case 1:
// Gallery fragment activity
FragmentTwo fragment2 = new FragmentTwo();
fragment2.setArguments(bund);
return fragment2;
case 2:
//Audio fragment
FragmentThree fragment3 = new FragmentThree();
fragment3.setArguments(bund);
return fragment3;
}
return null;
}
,而片段代码放在onCreateView方法
中Bundle bundle = getArguments();
if (bundle!=null){
prof = bundle.getInt("prof");
id = bundle.getInt("id");
}
我可以读取进入片段容器的参数,但是进入片段我无法读取它们,我忘记了什么?