gpt4 book ai didi

java - 如何将 LinkedHashMap 从 FragmentPagerAdapter 传递到 Fragment?

转载 作者:太空宇宙 更新时间:2023-11-04 13:04:27 26 4
gpt4 key购买 nike

下面是使用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 扩展 Fragment

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
int fragmentNumber = getArguments().getInt(ARG_SECTION_NUMBER);
}

最佳答案

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");
}

Important: Employee implements java.io.Serializable

关于java - 如何将 LinkedHashMap 从 FragmentPagerAdapter 传递到 Fragment?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34619178/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com