我想将自定义对象的Arraylist从我的活动传递给我的片段,我试图通过Parcelable Arraylist传递它,但我无法做任何人可以帮忙吗?任何传递arraylist的方法都可以从活动到片段
我的代码
-cp
fragment1 oncreateview:检索
String driverId = jsonObject.getJSONArray("user_data").getJSONObject(count).getString("order_id");
String pickupaddress = jsonObject.getJSONArray("user_data").getJSONObject(count).getString("pickup_address");
String contact = jsonObject.getJSONArray("user_data").getJSONObject(count).getString("contact");
Log.d("HomeAcivity",": "+driverId+","+pickupaddress+","+contact);
singleton = new Singleton(driverId,pickupaddress,contact);
userDataParserArrayList.add(singleton);
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
Jobs jobs = new Jobs();
Bundle bundle = new Bundle();
bundle.putParcelableArrayList("Order",userDataParserArrayList);
jobs.setArguments(bundle);
fragmentTransaction.commit();
ParcableClass()它不是单例类,只有名称是singleton
userDataParserArrayList = getArguments().getParcelableArrayList("Order");
答案 0 :(得分:0)
@bipin首先,您需要将片段添加到活动中,如下面的代码
Jobs jobs = new Jobs();
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.add("JOB_FRAGEMENT", jobs).commit();
创建" 作业片段"您可以从您的活动中访问arrayList,如下面的代码
((YourActivityName)getActivity()).yourArrayList(); in onViewCreated() method;
然后使用此列表!!!