0
我想在Android中使用带有选项卡的Swipe View,并且需要将某些变量传递给选项卡片段以显示自定义内容,我的问题是我总是将绑定为0,所以我认为我在从分段容器页面发送额外信息时出错。这是包含选项卡的片段和主片段页面的代码。如何在SwipeView活动中向片段发送/接收额外信息
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");
}
我可以读取进入片段容器,但到我无法读取它们的片段中的论点,我怎么忘了?