下面是使用args.putInt.
传递Int值的示例。同样,我想传递employee_map
。如何将Map对象作为Bundle args传递给Fragments。我不想以列表的形式传递。
MyFragmentPageAdapter扩展了FragmentPagerAdapter
@Override
public Fragment getItem(int position) {
LinkedHashMap<String,Employee> employee_map;
Fragment fragment = new DummySectionFragment();
Bundle args = new Bundle();
args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, position);
fragment.setArguments(args);
return fragment;
}
MyFragment扩展片段
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
int fragmentNumber = getArguments().getInt(ARG_SECTION_NUMBER);
}
答案 0 :(得分:0)
MyFragmentPageAdapter
@Override
public Fragment getItem(int position) {
LinkedHashMap<String,Employee> employee_map;
Fragment fragment = new DummySectionFragment();
Bundle args = new Bundle();
args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, position);
args.putSerializable("employee_map", employee_map);
fragment.setArguments(args);
return fragment;
}
MyFragment.java
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
int fragmentNumber = getArguments().getInt(ARG_SECTION_NUMBER);
employee_map = (LinkedHashMap<String, Employee>) getArguments().getSerializable("employee_map");
}
重要提示:
Employee
实施java.io.Serializable