购物车
——————————————————————
Main3Activity
——————————————————————
package com.example.myapplication.shopping; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Button; import android.widget.CheckBox; import android.widget.TextView; import android.widget.Toast; import com.example.myapplication.DingDan.Main5Activity; import com.example.myapplication.R; import com.example.myapplication.shopping.List.CountPriceBean; import com.example.myapplication.shopping.List.MyAdapter; import com.example.myapplication.shopping.List.MyEList; import java.util.List; public class Main3Activity extends AppCompatActivity implements ShoppingIMain3Activity { private MyShoppingPresent myShoppingPresent; private MyEList main3_list; private MyAdapter myAdapter; private CheckBox main3_checkall; Handler handler=new Handler(){ @Override public void handleMessage(Message msg) { if (msg.what == 0){ CountPriceBean countPriceBean = (CountPriceBean) msg.obj; //设置价格和数量 main3_sum.setText("合计:¥"+countPriceBean.getPriceString()); } } }; private TextView main3_sum; private Button main3_btn; @Override public void Onsuccess(final ShoppingBean shoppingBean) { if(shoppingBean!=null){ runOnUiThread(new Runnable() { @Override public void run() { myAdapter = new MyAdapter(shoppingBean,Main3Activity.this,myShoppingPresent,handler); main3_list.setAdapter(myAdapter); //展开列表 for (int i=0;i<shoppingBean.getData().size();i++){ main3_list.expandGroup(i); final List<ShoppingBean.DataBean.ListBean> list = shoppingBean.getData().get(i).getList(); shoppingBean.getData().get(i).setGroup_check(isAllChildInGroupChecked(list)); main3_checkall.setChecked(isAllGroupChecked(shoppingBean)); } } }); myAdapter.sendPriceAndCount(); //结算:跳转到订单页面 main3_btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent1=new Intent(Main3Activity.this, Main5Activity.class); startActivity(intent1); } }); }else{ runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(Main3Activity.this,"购物车已空",Toast.LENGTH_LONG).show(); } }); } } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main3); myShoppingPresent = new MyShoppingPresent(this); myShoppingPresent.data(); main3_checkall = findViewById(R.id.main3_checkall); main3_list = findViewById(R.id.main3_list); main3_list.setGroupIndicator(null); main3_sum = findViewById(R.id.main3_sum); main3_btn = findViewById(R.id.main3_btn); //全选按钮 main3_checkall.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { myAdapter.setAllChildsChecked(main3_checkall.isChecked()); } }); } //所有组checkbox是否选中 private boolean isAllGroupChecked(ShoppingBean shoppingBean) { for (int i=0;i<shoppingBean.getData().size();i++){ //只要有一个组未选中 返回false if (! shoppingBean.getData().get(i).isGroup_check()){ return false; } } return true; } //所有儿子checkbox是否选中 private boolean isAllChildInGroupChecked(List<ShoppingBean.DataBean.ListBean> listBeans) { for (int i=0;i<listBeans.size();i++){ if (listBeans.get(i).getSelected() == 0){ return false; } } return true; } }
——————————————————————————————————————
MyModle
——————————————————————————————————-————
package com.example.myapplication.shopping; import com.google.gson.Gson; import java.io.IOException; import okhttp3.Call; import okhttp3.Callback; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; /** * Created by dyz on 2018/1/16/0016. */ public class MyShoppingModle { private ShoppingIMyPresent shoppingIMyPresent; public MyShoppingModle(ShoppingIMyPresent shoppingIMyPresent) { this.shoppingIMyPresent=shoppingIMyPresent; } public void data(){ OkHttpClient okHttpClient=new OkHttpClient(); Request build = new Request.Builder().url("https://www.zhaoapi.cn/product/getCarts?uid=72&source=android").build(); Call call = okHttpClient.newCall(build); call.enqueue(new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { if(response.isSuccessful()){ String string = response.body().string(); if(string!=null){ ShoppingBean shoppingBean = new Gson().fromJson(string, ShoppingBean.class); shoppingIMyPresent.OnSuccess(shoppingBean); } else{ shoppingIMyPresent.OnSuccess(null); } } } }); } }
————————————————————————————————————
MyPersenter
————————————————————————————————————————
package com.example.myapplication.shopping; /** * Created by dyz on 2018/1/16/0016. */ public class MyShoppingPresent implements ShoppingIMyPresent { private ShoppingIMain3Activity shoppingIMain3Activity; private final MyShoppingModle myShoppingModle; public MyShoppingPresent(ShoppingIMain3Activity shoppingIMain3Activity) { this.shoppingIMain3Activity=shoppingIMain3Activity; myShoppingModle = new MyShoppingModle(this); } @Override public void OnSuccess(ShoppingBean shoppingBean) { shoppingIMain3Activity.Onsuccess(shoppingBean); } public void data(){ myShoppingModle.data(); } }——————————————————————————————————————————MyElist——————————————————————————————————————————package com.example.myapplication.shopping.List; import android.content.Context; import android.util.AttributeSet; import android.widget.ExpandableListView; import static com.example.myapplication.R.attr.height; /** * Created by dyz on 2018/1/16/0016. */ public class MyEList extends ExpandableListView { public MyEList(Context context) { super(context); } public MyEList(Context context, AttributeSet attrs) { super(context, attrs); } public MyEList(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE>>2,MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec,height); } }——————————————————————————————————————————二级列表适配器MyAdapter——————————————————————————————————————————package com.example.myapplication.shopping.List; import android.content.Context; import android.os.Handler; import android.os.Message; import android.view.View; import android.view.ViewGroup; import android.widget.BaseExpandableListAdapter; import android.widget.Button; import android.widget.CheckBox; import android.widget.ImageView; import android.widget.TextView; import com.bumptech.glide.Glide; import com.example.myapplication.R; import com.example.myapplication.shopping.MyShoppingPresent; import com.example.myapplication.shopping.ShoppingBean; import java.io.IOException; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import okhttp3.Call; import okhttp3.Callback; import okhttp3.FormBody; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; /** * Created by dyz on 2018/1/16/0016. */ public class MyAdapter extends BaseExpandableListAdapter { ShoppingBean shoppingBean; Context context; private int index; MyShoppingPresent myShoppingPresent; private List<ShoppingBean.DataBean.ListBean> list; private int allIndex; private Handler handler; public MyAdapter(ShoppingBean shoppingBean, Context context,MyShoppingPresent myShoppingPresent,Handler handler) { this.shoppingBean = shoppingBean; this.context = context; this.myShoppingPresent=myShoppingPresent; this.handler=handler; } public void sendPriceAndCount() { double price = 0; int count = 0; for (int i = 0;i<shoppingBean.getData().size();i++){ List<ShoppingBean.DataBean.ListBean> listBeans = shoppingBean.getData().get(i).getList(); for (int j = 0; j< listBeans.size(); j++){ if (listBeans.get(j).getSelected() == 1){ price += listBeans.get(j).getBargainPrice() * listBeans.get(j).getNum(); count += listBeans.get(j).getNum(); } } } //double高精度,,,计算的时候可能会出现一串数字...保留两位 DecimalFormat decimalFormat = new DecimalFormat("0.00"); String priceString = decimalFormat.format(price); CountPriceBean countPriceBean = new CountPriceBean(priceString, count); //发送到主页面进行显示 Message msg = Message.obtain(); msg.what = 0; msg.obj = countPriceBean; handler.sendMessage(msg); } @Override public int getGroupCount() { return shoppingBean.getData().size(); } @Override public int getChildrenCount(int i) { return shoppingBean.getData().get(i).getList().size(); } @Override public Object getGroup(int i) { return shoppingBean.getData().get(i); } @Override public Object getChild(int i, int i1) { return shoppingBean.getData().get(i).getList().get(i); } @Override public long getGroupId(int i) { return i; } @Override public long getChildId(int i, int i1) { return i1; } @Override public boolean hasStableIds() { return true; } @Override public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) { View inflate = View.inflate(context, R.layout.group_layout, null); TextView group_title=inflate.findViewById(R.id.group_title); final CheckBox group_check=inflate.findViewById(R.id.group_check); group_title.setText(shoppingBean.getData().get(i).getSellerName()); final ShoppingBean.DataBean dataBean = shoppingBean.getData().get(i); group_check.setChecked(dataBean.isGroup_check()); group_check.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { index = 0; updateAllChildInGroup(dataBean,group_check.isChecked()); } }); return inflate; } public void setAllChildsChecked(boolean checked) { //创建一个大的结合,,,存放所有商品的数据 List<ShoppingBean.DataBean.ListBean> allList = new ArrayList<>(); for (int i= 0;i<shoppingBean.getData().size();i++){ List<ShoppingBean.DataBean.ListBean> listBeans = shoppingBean.getData().get(i).getList(); for (int j=0;j<listBeans.size();j++){ allList.add(listBeans.get(j)); } } //显示progress //递归更新.... allIndex = 0; updateAllChecked(allList,checked); } private void updateAllChecked(final List<ShoppingBean.DataBean.ListBean> allList, final boolean checked) { ShoppingBean.DataBean.ListBean listBean = allList.get(allIndex); Map<String, String> params = new HashMap<>(); //?uid=71&sellerid=1&pid=1&selected=0&num=10 params.put("uid", "3690"); params.put("sellerid", String.valueOf(listBean.getSellerid())); params.put("pid", String.valueOf(listBean.getPid())); params.put("selected", String.valueOf(checked ? 1 : 0)); params.put("num", String.valueOf(listBean.getNum())); OkHttpClient okHttpClient = new OkHttpClient(); FormBody formBody = new FormBody.Builder().add("uid", "72") .add("sellerid", String.valueOf(listBean.getSellerid())) .add("pid", String.valueOf(listBean.getPid())) .add("selected", String.valueOf(checked ? 1 : 0)) .add("num", String.valueOf(listBean.getNum())).build(); Request build = new Request.Builder().url("https://www.zhaoapi.cn/product/updateCarts").post(formBody).build(); Call call = okHttpClient.newCall(build); call.enqueue(new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { if (response.isSuccessful()) { allIndex ++; if (allIndex < allList.size()){ //继续更新下一条 updateAllChecked(allList,checked); }else { //重新查询 myShoppingPresent.data(); } } } }); } private void updateAllChildInGroup(final ShoppingBean.DataBean dataBean, final boolean checked) { ShoppingBean.DataBean.ListBean listBean = dataBean.getList().get(index); OkHttpClient okHttpClient=new OkHttpClient(); FormBody formBody=new FormBody.Builder().add("uid","72") .add("sellerid",String.valueOf(listBean.getSellerid())) .add("pid",String.valueOf(listBean.getPid())) .add("selected",String.valueOf(checked? 1:0)) .add("num",String.valueOf(listBean.getNum())).build(); Request build = new Request.Builder().url("https://www.zhaoapi.cn/product/updateCarts").post(formBody).build(); Call call = okHttpClient.newCall(build); call.enqueue(new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { if(response.isSuccessful()){ index++; if(index<dataBean.getList().size()) { updateAllChildInGroup(dataBean,checked); } else{ myShoppingPresent.data(); } } } }); } @Override public View getChildView(final int i, final int i1, final boolean b, View view, ViewGroup viewGroup) { View inflate = View.inflate(context, R.layout.child_layout, null); TextView child__title=inflate.findViewById(R.id.child_title); CheckBox child__check=inflate.findViewById(R.id.child_check); ImageView child_image=inflate.findViewById(R.id.child_image); TextView child__price=inflate.findViewById(R.id.child_price); TextView child_count=inflate.findViewById(R.id.child_count); Button child_jia=inflate.findViewById(R.id.child_jia); Button child_delete=inflate.findViewById(R.id.child_delete); Button child_jian=inflate.findViewById(R.id.child_jian); child__price.setText("¥"+shoppingBean.getData().get(i).getList().get(i1).getPrice()); child__title.setText(shoppingBean.getData().get(i).getList().get(i1).getTitle()); String[] split = shoppingBean.getData().get(i).getList().get(i1).getImages().split("\\|"); Glide.with(context).load(split[0]).into(child_image); child_count.setText(shoppingBean.getData().get(i).getList().get(i1).getNum()+""); //选中复选框 child__check.setChecked(shoppingBean.getData().get(i).getList().get(i1).getSelected()==0? false:true); //儿子复选框 child__check.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { OkHttpClient okHttpClient=new OkHttpClient(); FormBody formBody=new FormBody.Builder().add("uid","72") .add("sellerid",String.valueOf(shoppingBean.getData().get(i).getList().get(i1).getSellerid())) .add("pid",String.valueOf(shoppingBean.getData().get(i).getList().get(i1).getPid())) .add("selected",String.valueOf(shoppingBean.getData().get(i).getList().get(i1).getSelected()==0? 1:0)) .add("num",String.valueOf(shoppingBean.getData().get(i).getList().get(i1).getNum())).build(); Request build = new Request.Builder().url("https://www.zhaoapi.cn/product/updateCarts").post(formBody).build(); Call call = okHttpClient.newCall(build); call.enqueue(new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { if(response.isSuccessful()){ myShoppingPresent.data(); } } }); } }); //删除商品 child_delete.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { OkHttpClient okHttpClient=new OkHttpClient(); FormBody formBody=new FormBody.Builder().add("uid","72") .add("pid",String.valueOf(shoppingBean.getData().get(i).getList().get(i1).getPid())).build(); Request build = new Request.Builder().url("https://www.zhaoapi.cn/product/deleteCart").post(formBody).build(); Call call = okHttpClient.newCall(build); call.enqueue(new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { if(response.isSuccessful()){ myShoppingPresent.data(); } } }); } }); //增加数量 child_jia.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { OkHttpClient okHttpClient=new OkHttpClient(); FormBody formBody=new FormBody.Builder().add("uid","72") .add("sellerid",String.valueOf(shoppingBean.getData().get(i).getList().get(i1).getSellerid())) .add("pid",String.valueOf(shoppingBean.getData().get(i).getList().get(i1).getPid())) .add("selected",String.valueOf(shoppingBean.getData().get(i).getList().get(i1).getSelected())) .add("num",String.valueOf(shoppingBean.getData().get(i).getList().get(i1).getNum()+1)).build(); Request build = new Request.Builder().url("https://www.zhaoapi.cn/product/updateCarts").post(formBody).build(); Call call = okHttpClient.newCall(build); call.enqueue(new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { if(response.isSuccessful()){ myShoppingPresent.data(); } } }); } }); //减少数量 child_jian.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { OkHttpClient okHttpClient=new OkHttpClient(); FormBody formBody=new FormBody.Builder().add("uid","72") .add("sellerid",String.valueOf(shoppingBean.getData().get(i).getList().get(i1).getSellerid())) .add("pid",String.valueOf(shoppingBean.getData().get(i).getList().get(i1).getPid())) .add("selected",String.valueOf(shoppingBean.getData().get(i).getList().get(i1).getSelected())) .add("num",String.valueOf(shoppingBean.getData().get(i).getList().get(i1).getNum()-1)).build(); Request build = new Request.Builder().url("https://www.zhaoapi.cn/product/updateCarts").post(formBody).build(); Call call = okHttpClient.newCall(build); call.enqueue(new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { if(response.isSuccessful()){ myShoppingPresent.data(); } } }); } }); return inflate; } @Override public boolean isChildSelectable(int i, int i1) { return true; } }————————————————————————————————————————CountPriceBean——————————————————————————————————————————package com.example.myapplication.shopping.List; /** * Created by dyz on 2018/1/16/0016. */ public class CountPriceBean { private String priceString; private int count; public CountPriceBean(String priceString, int count) { this.priceString = priceString; this.count = count; } public String getPriceString() { return priceString; } public void setPriceString(String priceString) { this.priceString = priceString; } public int getCount() { return count; } public void setCount(int count) { this.count = count; } }——————————————————————————————————————shoppingBean——————————————————————————————————————package com.example.myapplication.shopping; import java.util.List; /** * Created by dyz on 2018/1/16/0016. */ public class ShoppingBean { /** * code : 0 * data : [{"list":[{"bargainPrice":99,"createtime":"2017-10-14T21:38:26","detailUrl":"https://item.m.jd.com/product/4345173.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t6037/35/2944615848/95178/6cd6cff0/594a3a10Na4ec7f39.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t6607/258/1025744923/75738/da120a2d/594a3a12Ne3e6bc56.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t6370/292/1057025420/64655/f87644e3/594a3a12N5b900606.jpg!q70.jpg","num":1,"pid":45,"price":2999,"pscid":39,"selected":0,"sellerid":1,"subhead":"高清双摄,就是清晰!2000+1600万高清摄像头,6GB大内存+高通骁龙835处理器,性能怪兽!","title":"一加手机5 (A5000) 6GB+64GB 月岩灰 全网通 双卡双待 移动联通电信4G手机"},{"bargainPrice":159,"createtime":"2017-10-14T21:49:15","detailUrl":"https://item.m.jd.com/product/5061723.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t8716/197/1271594444/173291/2f40bb4f/59b743bcN8509428e.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8347/264/1286771527/92188/5cf5ec04/59b7420fN65378e9e.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7363/165/3000956253/190883/179a372/59b743bfNd0c79d93.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7399/112/2935531768/183594/b77c7d4a/59b7441aNc3d40133.jpg!q70.jpg","num":1,"pid":90,"price":1233,"pscid":112,"selected":0,"sellerid":1,"subhead":"针织针织闪闪闪亮你的眼","title":"维迩旎 2017秋冬新款长袖针织连衣裙韩版气质中长款名媛包臀A字裙 zx179709 黑色 XL"}],"sellerName":"商家1","sellerid":"1"},{"list":[{"bargainPrice":11800,"createtime":"2017-10-14T21:38:26","detailUrl":"https://item.m.jd.com/product/5025518.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t8830/106/1760940277/195595/5cf9412f/59bf2ef5N5ab7dc16.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5428/70/1520969931/274676/b644dd0d/591128e7Nd2f70da0.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5566/365/1519564203/36911/620c750c/591128eaN54ac3363.jpg!q70.jpg","num":1,"pid":58,"price":6399,"pscid":40,"selected":0,"sellerid":2,"subhead":"升级4G大显存!Nvme协议Pcie SSD,速度快人一步】GTX1050Ti就选拯救者!专业游戏键盘&新模具全新设计!","title":"联想(Lenovo)拯救者R720 15.6英寸游戏笔记本电脑(i5-7300HQ 8G 1T+128G SSD GTX1050Ti 4G IPS 黑)"},{"bargainPrice":159,"createtime":"2017-10-14T21:49:15","detailUrl":"https://item.m.jd.com/product/5061723.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t8716/197/1271594444/173291/2f40bb4f/59b743bcN8509428e.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8347/264/1286771527/92188/5cf5ec04/59b7420fN65378e9e.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7363/165/3000956253/190883/179a372/59b743bfNd0c79d93.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7399/112/2935531768/183594/b77c7d4a/59b7441aNc3d40133.jpg!q70.jpg","num":1,"pid":91,"price":1344,"pscid":112,"selected":0,"sellerid":2,"subhead":"针织针织闪闪闪亮你的眼","title":"维迩旎 2017秋冬新款长袖针织连衣裙韩版气质中长款名媛包臀A字裙 zx179709 黑色 XL"}],"sellerName":"商家2","sellerid":"2"},{"list":[{"bargainPrice":1599,"createtime":"2017-10-14T21:48:08","detailUrl":"https://item.m.jd.com/product/1993026402.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t5863/302/8961270302/97126/41feade1/5981c81cNc1b1fbef.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7003/250/1488538438/195825/53bf31ba/5981c57eN51e95176.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5665/100/8954482513/43454/418611a9/5981c57eNd5fc97ba.jpg!q70.jpg","num":2,"pid":47,"price":111,"pscid":39,"selected":0,"sellerid":3,"subhead":"碳黑色 32GB 全网通 官方标配 1件","title":"锤子 坚果Pro 特别版 巧克力色 酒红色 全网通 移动联通电信4G手机 双卡双待 碳黑色 32GB 全网通"},{"bargainPrice":5599,"createtime":"2017-10-10T17:30:32","detailUrl":"https://item.m.jd.com/product/4824715.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n12/jfs/t7768/184/1153704394/148460/f42e1432/599a930fN8a85626b.jpg!q70.jpg","num":1,"pid":59,"price":5599,"pscid":40,"selected":0,"sellerid":3,"subhead":"游戏本选择4G独显,拒绝掉帧】升级版IPS全高清防眩光显示屏,WASD方向键颜色加持,三大出风口立体散热!","title":"戴尔DELL灵越游匣15PR-6648B GTX1050 15.6英寸游戏笔记本电脑(i5-7300HQ 8G 128GSSD+1T 4G独显 IPS)黑"}],"sellerName":"商家3","sellerid":"3"},{"list":[{"bargainPrice":3455,"createtime":"2017-10-14T21:38:26","detailUrl":"https://item.m.jd.com/product/12224420750.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t9106/106/1785172479/537280/253bc0ab/59bf78a7N057e5ff7.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t9106/106/1785172479/537280/253bc0ab/59bf78a7N057e5ff7.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8461/5/1492479653/68388/7255e013/59ba5e84N91091843.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8461/5/1492479653/68388/7255e013/59ba5e84N91091843.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8803/356/1478945529/489755/2a163ace/59ba5e84N7bb9a666.jpg!q70.jpg","num":3,"pid":48,"price":222,"pscid":39,"selected":0,"sellerid":4,"subhead":"【现货新品抢购】全面屏2.0震撼来袭,骁龙835处理器,四曲面陶瓷机","title":"小米(MI) 小米MIX2 手机 黑色 全网通 (6GB+64GB)【标配版】"},{"bargainPrice":399,"createtime":"2017-10-14T21:38:26","detailUrl":"https://item.m.jd.com/product/1439822107.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t5887/201/859509257/69994/6bde9bf6/59224c24Ne854e14c.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5641/233/853609022/57374/5c73d281/59224c24N3324d5f4.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5641/233/853609022/57374/5c73d281/59224c24N3324d5f4.jpg!q70.jpg","num":1,"pid":83,"price":444,"pscid":85,"selected":0,"sellerid":4,"subhead":"满2件,总价打6.50折","title":"Gap男装 休闲舒适简约水洗五袋直筒长裤紧身牛仔裤941825 深灰色 33/32(175/84A)"}],"sellerName":"商家4","sellerid":"4"},{"list":[{"bargainPrice":1999,"createtime":"2017-10-10T16:09:02","detailUrl":"https://item.m.jd.com/product/5025971.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t7210/232/3738666823/232298/9004583e/59c3a9a7N8de42e15.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8356/82/2107423621/109733/c019b8c6/59c3a9a6Ne9a4bdd7.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t10219/74/25356012/171379/7d55e296/59c3a9a8N82fa6e02.jpg!q70.jpg","num":2,"pid":49,"price":333,"pscid":39,"selected":0,"sellerid":5,"subhead":"vivo X20 带你开启全面屏时代!逆光也清晰,照亮你的美!","title":"vivo X20 全面屏手机 全网通 4GB+64GB 金色 移动联通电信4G手机 双卡双待"}],"sellerName":"商家5","sellerid":"5"},{"list":[{"bargainPrice":3455,"createtime":"2017-10-14T21:48:08","detailUrl":"https://item.m.jd.com/product/12224420750.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t9106/106/1785172479/537280/253bc0ab/59bf78a7N057e5ff7.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t9106/106/1785172479/537280/253bc0ab/59bf78a7N057e5ff7.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8461/5/1492479653/68388/7255e013/59ba5e84N91091843.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8461/5/1492479653/68388/7255e013/59ba5e84N91091843.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8803/356/1478945529/489755/2a163ace/59ba5e84N7bb9a666.jpg!q70.jpg","num":2,"pid":50,"price":444,"pscid":39,"selected":0,"sellerid":6,"subhead":"【现货新品抢购】全面屏2.0震撼来袭,骁龙835处理器,四曲面陶瓷机","title":"小米(MI) 小米MIX2 手机 黑色 全网通 (6GB+64GB)【标配版】"}],"sellerName":"商家6","sellerid":"6"},{"list":[{"bargainPrice":3455,"createtime":"2017-10-14T21:38:26","detailUrl":"https://item.m.jd.com/product/12224420750.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t9106/106/1785172479/537280/253bc0ab/59bf78a7N057e5ff7.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t9106/106/1785172479/537280/253bc0ab/59bf78a7N057e5ff7.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8461/5/1492479653/68388/7255e013/59ba5e84N91091843.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8461/5/1492479653/68388/7255e013/59ba5e84N91091843.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8803/356/1478945529/489755/2a163ace/59ba5e84N7bb9a666.jpg!q70.jpg","num":1,"pid":51,"price":555,"pscid":39,"selected":0,"sellerid":7,"subhead":"【现货新品抢购】全面屏2.0震撼来袭,骁龙835处理器,四曲面陶瓷机","title":"小米(MI) 小米MIX2 手机 黑色 全网通 (6GB+64GB)【标配版】"}],"sellerName":"商家7","sellerid":"7"},{"list":[{"bargainPrice":111.99,"createtime":"2017-10-14T21:39:05","detailUrl":"https://item.m.jd.com/product/4719303.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t9004/210/1160833155/647627/ad6be059/59b4f4e1N9a2b1532.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7504/338/63721388/491286/f5957f53/598e95f1N7f2adb87.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7441/10/64242474/419246/adb30a7d/598e95fbNd989ba0a.jpg!q70.jpg","num":1,"pid":1,"price":118,"pscid":1,"selected":0,"sellerid":17,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellerName":"商家17","sellerid":"17"}] * msg : 请求成功 */ private String code; private String msg; private List<DataBean> data; public String getCode() { return code; } public void setCode(String code) { this.code = code; } public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } public List<DataBean> getData() { return data; } public void setData(List<DataBean> data) { this.data = data; } public static class DataBean { /** * list : [{"bargainPrice":99,"createtime":"2017-10-14T21:38:26","detailUrl":"https://item.m.jd.com/product/4345173.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t6037/35/2944615848/95178/6cd6cff0/594a3a10Na4ec7f39.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t6607/258/1025744923/75738/da120a2d/594a3a12Ne3e6bc56.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t6370/292/1057025420/64655/f87644e3/594a3a12N5b900606.jpg!q70.jpg","num":1,"pid":45,"price":2999,"pscid":39,"selected":0,"sellerid":1,"subhead":"高清双摄,就是清晰!2000+1600万高清摄像头,6GB大内存+高通骁龙835处理器,性能怪兽!","title":"一加手机5 (A5000) 6GB+64GB 月岩灰 全网通 双卡双待 移动联通电信4G手机"},{"bargainPrice":159,"createtime":"2017-10-14T21:49:15","detailUrl":"https://item.m.jd.com/product/5061723.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t8716/197/1271594444/173291/2f40bb4f/59b743bcN8509428e.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8347/264/1286771527/92188/5cf5ec04/59b7420fN65378e9e.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7363/165/3000956253/190883/179a372/59b743bfNd0c79d93.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7399/112/2935531768/183594/b77c7d4a/59b7441aNc3d40133.jpg!q70.jpg","num":1,"pid":90,"price":1233,"pscid":112,"selected":0,"sellerid":1,"subhead":"针织针织闪闪闪亮你的眼","title":"维迩旎 2017秋冬新款长袖针织连衣裙韩版气质中长款名媛包臀A字裙 zx179709 黑色 XL"}] * sellerName : 商家1 * sellerid : 1 */ //注意...需要自己添加一个booelan类型的字段,,,表示商家(一级列表是否选中) private boolean group_check; public boolean isGroup_check() { return group_check; } public void setGroup_check(boolean group_check) { this.group_check = group_check; } private String sellerName; private String sellerid; private List<ListBean> list; public String getSellerName() { return sellerName; } public void setSellerName(String sellerName) { this.sellerName = sellerName; } public String getSellerid() { return sellerid; } public void setSellerid(String sellerid) { this.sellerid = sellerid; } public List<ListBean> getList() { return list; } public void setList(List<ListBean> list) { this.list = list; } public static class ListBean { /** * bargainPrice : 99.0 * createtime : 2017-10-14T21:38:26 * detailUrl : https://item.m.jd.com/product/4345173.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends * images : https://m.360buyimg.com/n0/jfs/t6037/35/2944615848/95178/6cd6cff0/594a3a10Na4ec7f39.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t6607/258/1025744923/75738/da120a2d/594a3a12Ne3e6bc56.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t6370/292/1057025420/64655/f87644e3/594a3a12N5b900606.jpg!q70.jpg * num : 1 * pid : 45 * price : 2999.0 * pscid : 39 * selected : 0 * sellerid : 1 * subhead : 高清双摄,就是清晰!2000+1600万高清摄像头,6GB大内存+高通骁龙835处理器,性能怪兽! * title : 一加手机5 (A5000) 6GB+64GB 月岩灰 全网通 双卡双待 移动联通电信4G手机 */ private double bargainPrice; private String createtime; private String detailUrl; private String images; private int num; private int pid; private double price; private int pscid; private int selected;//当前的商品子条目是否选中....1表示选中,0未选中 private int sellerid; private String subhead; private String title; public double getBargainPrice() { return bargainPrice; } public void setBargainPrice(double bargainPrice) { this.bargainPrice = bargainPrice; } public String getCreatetime() { return createtime; } public void setCreatetime(String createtime) { this.createtime = createtime; } public String getDetailUrl() { return detailUrl; } public void setDetailUrl(String detailUrl) { this.detailUrl = detailUrl; } public String getImages() { return images; } public void setImages(String images) { this.images = images; } public int getNum() { return num; } public void setNum(int num) { this.num = num; } public int getPid() { return pid; } public void setPid(int pid) { this.pid = pid; } public double getPrice() { return price; } public void setPrice(double price) { this.price = price; } public int getPscid() { return pscid; } public void setPscid(int pscid) { this.pscid = pscid; } public int getSelected() { return selected; } public void setSelected(int selected) { this.selected = selected; } public int getSellerid() { return sellerid; } public void setSellerid(int sellerid) { this.sellerid = sellerid; } public String getSubhead() { return subhead; } public void setSubhead(String subhead) { this.subhead = subhead; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } } } }——————————————————————————————————————————Main3Activity.xml——————————————————————————————————————————<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.myapplication.shopping.Main3Activity"> <ScrollView android:layout_width="wrap_content" android:layout_height="wrap_content"> <com.example.myapplication.shopping.List.MyEList android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/main3_list" ></com.example.myapplication.shopping.List.MyEList> </ScrollView> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_alignParentBottom="true" android:background="@android:color/white" > <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="全选" android:id="@+id/main3_checkall" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="合计:¥0.00" android:id="@+id/main3_sum" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="150dp" android:text="去结算" android:id="@+id/main3_btn" android:background="@android:color/holo_red_dark" android:textColor="@android:color/white" /> </LinearLayout> </RelativeLayout>————————————————————————————————————————child.xml————————————————————————————————————————<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" > <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/child_check" /> <ImageView android:layout_width="130dp" android:layout_height="130dp" android:id="@+id/child_image" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/child_title" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/child_price" android:textColor="@android:color/holo_red_dark" android:layout_marginTop="80dp" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="+" android:id="@+id/child_jia" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/child_count" android:text="1" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="-" android:id="@+id/child_jian" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="删除" android:id="@+id/child_delete" android:background="@android:color/holo_red_dark" android:textColor="@android:color/white" /> </LinearLayout> </LinearLayout> </LinearLayout> </LinearLayout>———————————————————————————————————————————