如何在适配器的arraylist中填充json数组项?

时间:2018-09-16 05:14:35

标签: android android-fragments arraylist android-recyclerview baseadapter

我正在解析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();

        }
    });

}

1 个答案:

答案 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实现