[英]Getting null values when passing data from activity to fragment using Parceable
I am trying to pass arraylist from activity to fragments but i am getting a null value using the parceable.我试图将 arraylist 从活动传递到片段,但我使用 parceable 获得了一个空值。
In Main Activity:在主要活动中:
Bundle bundle = new Bundle();
bundle.putParcelableArrayList("cbookings", customerbooking);
Todaybooking tb = new Todaybooking();
tb.setArguments(bundle);
Array list data declarations数组列表数据声明
ArrayList<Cbooking> customerbooking = new ArrayList<>();
In fragments:在片段中:
ArrayList<Cbooking> customerbooking = new ArrayList<>();
Bundle extras = getActivity().getIntent().getExtras();
customerbooking = extras.getParcelableArrayList("cbookings");
Log.wtf("test", customerbooking.toString());
You are using setArguments()
to pass the data into the fragment.您正在使用
setArguments()
将数据传递到片段中。 Therefore, you need to use getArguments()
to retrieve the data, not getActivity().getIntent().getExtras()
.因此,您需要使用
getArguments()
来检索数据,而不是getActivity().getIntent().getExtras()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.