说我有:
private Map<Integer,String> prices = new HashMap<Integer,String>();
private Map<Integer,String> titles = new HashMap<Integer,String>();
private Map<Integer,String> descriptions = new HashMap<Integer,String>();
private Map<Integer,String[]> pictures = new HashMap<Integer,String[]>();
我想通过捆绑包将这些转移到另一个片段:
Bundle bundle = new Bundle();
bundle.put //best way?
fragment.setArguments(bundle);
if (fragment != null) {
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.frame_container, fragment).commit();
}
最有效/最简单的方法是什么?
答案 0 :(得分:1)
在片段类中创建这些HashMap
的setter。然后用它将这些参数传递给片段。
fragment.setHashMaps(Map<Integer,String> prices, Map<Integer,String> titles, Map<Integer,String> descriptions, Map<Integer,String[]> pictures) {
this.prices = prices;
this.titles= titles;
this.descriptions = descriptions;
this.pictures = pictures;
}