gpt4 book ai didi

android - 如何将选定的自定义数组列表值放置到相同的自定义数组列表中,但最多只能放置 5 个中的 3 个

转载 作者:行者123 更新时间:2023-11-29 19:06:35 24 4
gpt4 key购买 nike

从响应中我得到总的(getListOfPackages)计划列表大小 5 它有 id 号 2,3,4,5 和 6,但我的要求我必须在一个 recyclerview 中显示计划 id 2,5 和 6 并保留在另一个回收者 View 。我没有从代码中得到我想要的东西,请检查我的代码并提供解决方案。谢谢

       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();
}

}

最佳答案

please check the ans for data list separation, adapter and recycler views needs to created.

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();
}

}

关于android - 如何将选定的自定义数组列表值放置到相同的自定义数组列表中,但最多只能放置 5 个中的 3 个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46998529/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com