问题描述
我正在尝试将arraylist从活动传递到片段,但是我使用parceable获得了空值。
在主要活动中:
Bundle bundle = new Bundle();
bundle.putParcelableArrayList("cbookings",customerbooking);
Todaybooking tb = new Todaybooking();
tb.setArguments(bundle);
数组列表数据声明
ArrayList<Cbooking> customerbooking = new ArrayList<>();
片段中:
ArrayList<Cbooking> customerbooking = new ArrayList<>();
Bundle extras = getActivity().getIntent().getExtras();
customerbooking = extras.getParcelableArrayList("cbookings");
Log.wtf("test",customerbooking.toString());
解决方法
您正在使用setArguments()
将数据传递到片段中。因此,您需要使用getArguments()
而不是getActivity().getIntent().getExtras()
来检索数据。