1

从响应中,我得到总计(getListOfPackages)计划列表大小 5,它的 ID 号为 2、3、4、5 和 6,但我的要求是我必须在一个回收站视图中显示计划 ID 2、5 和 6,并在另一个回收站视图中显示。我没有从代码中得到我想要的,请检查我的代码并给出解决方案。感谢你

       List<PlanGsonResponse.ListOfPackages> data=new ArrayList<>();
       ForFamilyList forFamilyList=new ForFamilyList();   
   public void loadData() {
    try {

        PlanGsonRequest planGsonRequest = new      PlanGsonRequest(Request.Method.GET, Constants.PACKAGES_API, null,
                new Response.Listener<PlanGsonResponse>() {

                    @Override
                    public void onResponse(PlanGsonResponse res) {
                        // TODO Auto-generated method stub

                        if (res != null) {
                            data=res.getListOfPackages();

                            for(int i=0;i<data.size();i++)
                            {
                                if (data.get(i).getPackageID()==2||data.get(i).getPackageID()==5||data.get(i).getPackageID()==6)
                                {
                                    forFamilyList.setPackageID(data.get(i).getPackageID());
                                    forFamilyList.setPackageName(data.get(i).getPackageName());
                                    forFamilyList.setAvailableServicesUnderPackage(data.get(i).getAvailableServicesUnderPackage());
                                    forFamilyList.setHealthCheckupsUnderPackage(data.get(i).getHealthCheckupsUnderPackage());
                                    forFamilyList.setPackagePrice(data.get(i).getPackageCost());

                                }
                               forFamilyPackes.add(forFamilyList);


                            }
                            planlistfragmentadapter=new Planlistfragmentadapter(PlanListFragmentNew.this, mContext,forFamilyPackes);
                            mPackagelistRecyclerView.setAdapter(planlistfragmentadapter);

                            String sbid = res.toString();
                            Log.e("arrAY",data.toString());
                            Log.d("hello","hello"+res.getListOfPackages());


                        }  else {
                            Toast.makeText(getActivity(), "Success", Toast.LENGTH_LONG).show();
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError res) {
                // TODO Auto-generated method stub
            }
        }
                , null, PlanGsonResponse.class,
                Request.Priority.IMMEDIATE);
        RequestManager.getRequestQueue().add(planGsonRequest);




    } catch(
            Exception e)

    {
        e.printStackTrace();
    }

}
4

1 回答 1

2

请检查 ans 以了解需要创建的数据列表分离、适配器和回收器视图。

List<PlanGsonResponse.ListOfPackages> data=new ArrayList<>();
 List<ForFamilyList> forFamilyPackes1 =new ArrayList<>();
  List<ForFamilyList> forFamilyPackes2 =new ArrayList<>();
   //ForFamilyList forFamilyList=new ForFamilyList(); 

public void loadData() {
   try {

    PlanGsonRequest planGsonRequest = new      PlanGsonRequest(Request.Method.GET, Constants.PACKAGES_API, null,
            new Response.Listener<PlanGsonResponse>() {

                @Override
                public void onResponse(PlanGsonResponse res) {
                    // TODO Auto-generated method stub

                    if (res != null) {
                        data=res.getListOfPackages();

                        for(int i=0;i<data.size();i++)
                        {
 ForFamilyList forFamilyList=new ForFamilyList();
                            if (data.get(i).getPackageID()==2||data.get(i).getPackageID()==5||data.get(i).getPackageID()==6)
                            {

                                forFamilyList.setPackageID(data.get(i).getPackageID());
                                forFamilyList.setPackageName(data.get(i).getPackageName());
                                forFamilyList.setAvailableServicesUnderPackage(data.get(i).getAvailableServicesUnderPackage());
                                forFamilyList.setHealthCheckupsUnderPackage(data.get(i).getHealthCheckupsUnderPackage());
                                forFamilyList.setPackagePrice(data.get(i).getPackageCost());
  forFamilyPackes1.add(forFamilyList);
                            }else
                           forFamilyPackes2.add(forFamilyList);


                        }
  // here make changes for the adapter and recycler views 
                        planlistfragmentadapter=new Planlistfragmentadapter(PlanListFragmentNew.this, mContext,forFamilyPackes1);
                        mPackagelistRecyclerView.setAdapter(planlistfragmentadapter);

                        String sbid = res.toString();
                        Log.e("arrAY",data.toString());
                        Log.d("hello","hello"+res.getListOfPackages());


                    }  else {
                        Toast.makeText(getActivity(), "Success", Toast.LENGTH_LONG).show();
                    }
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError res) {
            // TODO Auto-generated method stub
        }
    }
            , null, PlanGsonResponse.class,
            Request.Priority.IMMEDIATE);
    RequestManager.getRequestQueue().add(planGsonRequest);




} catch(
        Exception e)

{
    e.printStackTrace();
}

 }
于 2017-10-29T09:29:18.263 回答