我正在解析JSON并将其显示在Recyclerview
中。现在,我想获取的是我所有JSON数据的Headertext
并将其填充到数组列表中,并将该数组列表传递给另一个片段。
@Override
public void onBindViewHolder(BuyerMemberValueAddedAdapter.SimpleViewHolder holder, final int position) {
BuyerMemberShipValueAddedModel mservicebenefits = new BuyerMemberShipValueAddedModel();
final ArrayList<BuyerMemberShipValueAddedModel> serviceinfobenefitList = new ArrayList<>();
for (int item = 0; item < serviceinfobenefitList.size(); item++) {
mservicebenefits.setValueAddedService_Headertxt(imagesList.get(position).getValueAddedService_Headertxt());
}
serviceinfobenefitList.addAll(Collections.singleton(mservicebenefits));
System.out.println("Service Texts"+serviceinfobenefitList.size());
holder.btngetstarted.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bundle args = new Bundle();
args.putSerializable("servicelist", serviceinfobenefitList);
//set Fragmentclass Arguments
SubmitOurValueAddedService fragobj = new SubmitOurValueAddedService();
fragobj.setArguments(args);
FragmentManager fragmentManager = currentFragment.getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(R.id.activity_home_fl_container, fragobj);
fragmentTransaction.hide(currentFragment);
fragmentTransaction.commit();
}
});
}
答案 0 :(得分:0)
像这样编辑您的代码:
for(int item = 0; item<serviceinfobenefitList.size(); item++)
{
mservicebenefits.setValueAddedService_Headertxt(imagesList.get(position).getValueAddedService_Headertxt());
serviceinfobenefitList.addAll(Collections.singleton(mservicebenefits));
}
以下是获取列表的方法:
Bundle bundle = getArguments();
BuyerMemberShipValueAddedModel buyerMemberShipValueAddedModel= (BuyerMemberShipValueAddedModel) bundle.getSerializable("servicelist");
您的BuyerMemberShipValueAddedModel模型必须通过Serializable实现