java用自定义对象数组列表实例化片段第二部分
嗨,我在stackoverflow中搜索了这个问题。我在这篇帖子里找到了一个
Instantiate a fragment with a Custom Object Array List
所有的答案都是序列化的或可打包的,我做了这个解决方案
我的问题是,好主意还是坏习惯
对象图标
public class IconItem {
private String name;
private int resId;
public IconItem(String name, int resId){
this.name = name;
this.resId = resId;
}
public String getName(){
return this.name;
}
public int getResId(){
return this.resId;
}
}
碎片
public class IconsFragment extends Fragment {
private ArrayList<IconItem> myList
public static IconsFragment newInstance(ArrayList<IconItem> list) {
IconsFragment fragment = new IconsFragment();
myList = list;
return fragment;
}
}
这样,当我引用片段时,我会传递ArrayList
对我来说,在另一个片段中使用RecyclerView
问候
共 (0) 个答案