依赖:
compile 'com.squareup.retrofit2:retrofit:2.3.0' compile 'com.squareup.retrofit2:converter-gson:2.3.0' compile 'io.reactivex.rxjava2:rxjava:2.1.7' compile 'io.reactivex.rxjava2:rxandroid:2.0.1' compile 'com.squareup.retrofit2:adapter-rxjava2:2.3.0' compile 'com.squareup.retrofit2:converter-scalars:+' compile 'com.github.bumptech.glide:glide:3.7.0'sha.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <stroke android:color="#999"/> <solid android:color="#fff"/> </shape>布局:
activity布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.yuemo.MainActivity"> <RelativeLayout android:id="@+id/re" android:layout_width="match_parent" android:layout_height="50dp"> <TextView android:id="@+id/t1" android:layout_centerVertical="true" android:layout_centerHorizontal="true" android:textSize="25sp" android:text="购物车" android:layout_width="wrap_content" android:layout_height="45dp" /> <TextView android:layout_below="@+id/t1" android:background="#999" android:layout_width="match_parent" android:layout_height="5dp" /> </RelativeLayout> <ExpandableListView android:id="@+id/expanable_listview" android:layout_below="@+id/re" android:layout_width="match_parent" android:layout_height="match_parent"></ExpandableListView> <RelativeLayout android:background="#755b5b" android:layout_alignParentBottom="true" android:layout_width="match_parent" android:layout_height="50dp"> <CheckBox android:id="@+id/check_all" android:layout_centerVertical="true" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:layout_marginLeft="35dp" android:layout_centerVertical="true" android:textSize="20sp" android:text="全选" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@+id/zongjia" android:layout_marginLeft="90dp" android:layout_centerVertical="true" android:textSize="20sp" android:text="合计:0" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@+id/zongshu" android:textColor="#fff" android:textSize="20sp" android:gravity="center" android:layout_alignParentRight="true" android:text="去结算(0)" android:background="#f00" android:layout_width="100dp" android:layout_height="match_parent" /> </RelativeLayout> </RelativeLayout>一级列表布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:orientation="horizontal" android:layout_height="70dp"> <CheckBox android:id="@+id/checkBox" android:layout_width="wrap_content" android:layout_height="40dp" /> <TextView android:id="@+id/group_text" android:textSize="25sp" android:textColor="#000" android:layout_width="match_parent" android:layout_height="40dp" /> </LinearLayout>二级布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="150dp" android:orientation="horizontal" > <CheckBox android:layout_marginTop="30dp" android:id="@+id/child_check" android:layout_width="wrap_content" android:layout_height="40dp" /> <ImageView android:id="@+id/child_imageview" android:layout_width="150dp" android:layout_height="150dp" /> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="150dp"> <TextView android:textSize="20sp" android:id="@+id/child_title" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="2" /> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" > <TextView android:textColor="#f00" android:textSize="15sp" android:id="@+id/child_price" android:layout_weight="2" android:layout_width="0dp" android:gravity="center" android:layout_height="match_parent" /> <TextView android:visibility="gone" android:textSize="20sp" android:id="@+id/tshu" android:text="数量:" android:layout_weight="1" android:layout_width="0dp" android:gravity="center" android:layout_height="match_parent" /> <LinearLayout android:id="@+id/numlinear" android:layout_weight="2" android:layout_width="0dp" android:layout_height="50dp"> <TextView android:gravity="center" android:id="@+id/child_jian" android:layout_marginTop="10dp" android:background="@drawable/sha" android:text="一" android:layout_width="20dp" android:layout_height="match_parent" /> <TextView android:id="@+id/child_num" android:layout_marginTop="10dp" android:layout_width="20dp" android:layout_height="match_parent" /> <TextView android:gravity="center" android:id="@+id/child_jia" android:layout_marginTop="10dp" android:background="@drawable/sha" android:text="十" android:layout_width="20dp" android:layout_height="match_parent" /> </LinearLayout> <Button android:id="@+id/delete" android:background="#f00" android:textColor="#fff" android:text="删除" android:layout_weight="1" android:layout_width="0dp" android:layout_height="match_parent" /> </LinearLayout> </LinearLayout> </LinearLayout>constant类:
public class Constant { public static final String Base_login="http://120.27.23.105/"; public static final String xiang="https://www.zhaoapi.cn/"; public static final String Base_search="https://www.zhaoapi.cn/"; public static final String Base4 ="https://www.zhaoapi.cn/"; public static final String Baseurl ="https://www.zhaoapi.cn/product/"; public static final String Base3 ="https://www.zhaoapi.cn/"; }pricebean:
public class PriceBean { private String price; private int count; public PriceBean(String price, int count) { this.price = price; this.count = count; } public String getPrice() { return price; } public void setPrice(String price) { this.price = price; } public int getCount() { return count; } public void setCount(int count) { this.count = count; } }shopbean:
public class ShopBean { /** * msg : 请求成功 * code : 0 * data : [{"list":[{"bargainPrice":6666,"createtime":"2017-10-10T16:01:31","detailUrl":"https://item.m.jd.com/product/5089273.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t8284/363/1326459580/71585/6d3e8013/59b857f2N6ca75622.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t9346/182/1406837243/282106/68af5b54/59b8480aNe8af7f5c.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8434/54/1359766007/56140/579509d9/59b85801Nfea207db.jpg!q70.jpg","num":8,"pid":46,"price":234,"pscid":39,"selected":1,"sellerid":2,"subhead":"【iPhone新品上市】新一代iPhone,让智能看起来更不一样","title":"Apple iPhone 8 Plus (A1864) 64GB 金色 移动联通电信4G手机"}],"sellerName":"商家2","sellerid":"2"},{"list":[{"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":6,"pid":59,"price":5599,"pscid":40,"selected":1,"sellerid":3,"subhead":"游戏本选择4G独显,拒绝掉帧】升级版IPS全高清防眩光显示屏,WASD方向键颜色加持,三大出风口立体散热!","title":"戴尔DELL灵越游匣15PR-6648B GTX1050 15.6英寸游戏笔记本电脑(i5-7300HQ 8G 128GSSD+1T 4G独显 IPS)黑"},{"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":1,"pid":47,"price":111,"pscid":39,"selected":1,"sellerid":3,"subhead":"碳黑色 32GB 全网通 官方标配 1件","title":"锤子 坚果Pro 特别版 巧克力色 酒红色 全网通 移动联通电信4G手机 双卡双待 碳黑色 32GB 全网通"}],"sellerName":"商家3","sellerid":"3"},{"list":[{"bargainPrice":11800,"createtime":"2017-10-14T21:48:08","detailUrl":"https://mitem.jd.hk/ware/view.action?wareId=1988853309&cachekey=1acb07a701ece8d2434a6ae7fa6870a1","images":"https://m.360buyimg.com/n0/jfs/t6130/97/1370670410/180682/1109582a/593276b1Nd81fe723.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5815/178/2614671118/51656/7f52d137/593276c7N107b725a.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5878/60/2557817477/30873/4502b606/593276caN5a7d6357.jpg!q70.jpg","num":1,"pid":60,"price":13888,"pscid":40,"selected":1,"sellerid":4,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"},{"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":48,"price":222,"pscid":39,"selected":1,"sellerid":4,"subhead":"【现货新品抢购】全面屏2.0震撼来袭,骁龙835处理器,四曲面陶瓷机","title":"小米(MI) 小米MIX2 手机 黑色 全网通 (6GB+64GB)【标配版】"},{"bargainPrice":22.9,"createtime":"2017-10-14T21:38:26","detailUrl":"https://item.m.jd.com/product/2542855.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t1930/284/2865629620/390243/e3ade9c4/56f0a08fNbd3a1235.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t2137/336/2802996626/155915/e5e90d7a/56f0a09cN33e01bd0.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t1882/31/2772215910/389956/c8dbf370/56f0a0a2Na0c86ea6.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t2620/166/2703833710/312660/531aa913/57709035N33857877.jpg!q70.jpg","num":3,"pid":27,"price":488,"pscid":2,"selected":1,"sellerid":4,"subhead":"三只松鼠零食特惠,专区满99减50,满199减100,火速抢购》","title":"三只松鼠 坚果炒货 零食奶油味 碧根果225g/袋"}],"sellerName":"商家4","sellerid":"4"},{"list":[{"bargainPrice":22.9,"createtime":"2017-10-03T23:53:28","detailUrl":"https://item.m.jd.com/product/2542855.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t1930/284/2865629620/390243/e3ade9c4/56f0a08fNbd3a1235.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t2137/336/2802996626/155915/e5e90d7a/56f0a09cN33e01bd0.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t1882/31/2772215910/389956/c8dbf370/56f0a0a2Na0c86ea6.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t2620/166/2703833710/312660/531aa913/57709035N33857877.jpg!q70.jpg","num":4,"pid":28,"price":599,"pscid":2,"selected":1,"sellerid":5,"subhead":"三只松鼠零食特惠,专区满99减50,满199减100,火速抢购》","title":"三只松鼠 坚果炒货 零食奶油味 碧根果225g/袋"}],"sellerName":"商家5","sellerid":"5"},{"list":[{"bargainPrice":22.9,"createtime":"2017-10-14T21:48:08","detailUrl":"https://item.m.jd.com/product/2542855.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t1930/284/2865629620/390243/e3ade9c4/56f0a08fNbd3a1235.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t2137/336/2802996626/155915/e5e90d7a/56f0a09cN33e01bd0.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t1882/31/2772215910/389956/c8dbf370/56f0a0a2Na0c86ea6.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t2620/166/2703833710/312660/531aa913/57709035N33857877.jpg!q70.jpg","num":2,"pid":29,"price":588,"pscid":2,"selected":1,"sellerid":6,"subhead":"三只松鼠零食特惠,专区满99减50,满199减100,火速抢购》","title":"三只松鼠 坚果炒货 零食奶油味 碧根果225g/袋"},{"bargainPrice":11800,"createtime":"2017-10-03T23:53:28","detailUrl":"https://mitem.jd.hk/ware/view.action?wareId=1988853309&cachekey=1acb07a701ece8d2434a6ae7fa6870a1","images":"https://m.360buyimg.com/n0/jfs/t6130/97/1370670410/180682/1109582a/593276b1Nd81fe723.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5815/178/2614671118/51656/7f52d137/593276c7N107b725a.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5878/60/2557817477/30873/4502b606/593276caN5a7d6357.jpg!q70.jpg","num":4,"pid":62,"price":15999,"pscid":40,"selected":1,"sellerid":6,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"}],"sellerName":"商家6","sellerid":"6"},{"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":2,"pid":14,"price":987,"pscid":1,"selected":1,"sellerid":7,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"},{"bargainPrice":22.9,"createtime":"2017-10-14T21:38:26","detailUrl":"https://item.m.jd.com/product/2542855.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t1930/284/2865629620/390243/e3ade9c4/56f0a08fNbd3a1235.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t2137/336/2802996626/155915/e5e90d7a/56f0a09cN33e01bd0.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t1882/31/2772215910/389956/c8dbf370/56f0a0a2Na0c86ea6.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t2620/166/2703833710/312660/531aa913/57709035N33857877.jpg!q70.jpg","num":1,"pid":30,"price":688,"pscid":2,"selected":1,"sellerid":7,"subhead":"三只松鼠零食特惠,专区满99减50,满199减100,火速抢购》","title":"三只松鼠 坚果炒货 零食奶油味 碧根果225g/袋"},{"bargainPrice":11800,"createtime":"2017-10-14T21:38:26","detailUrl":"https://mitem.jd.hk/ware/view.action?wareId=1988853309&cachekey=1acb07a701ece8d2434a6ae7fa6870a1","images":"https://m.360buyimg.com/n0/jfs/t6130/97/1370670410/180682/1109582a/593276b1Nd81fe723.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5815/178/2614671118/51656/7f52d137/593276c7N107b725a.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5878/60/2557817477/30873/4502b606/593276caN5a7d6357.jpg!q70.jpg","num":18,"pid":63,"price":10000,"pscid":40,"selected":1,"sellerid":7,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"}],"sellerName":"商家7","sellerid":"7"},{"list":[{"bargainPrice":22.9,"createtime":"2017-10-03T23:43:53","detailUrl":"https://item.m.jd.com/product/2542855.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t1930/284/2865629620/390243/e3ade9c4/56f0a08fNbd3a1235.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t2137/336/2802996626/155915/e5e90d7a/56f0a09cN33e01bd0.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t1882/31/2772215910/389956/c8dbf370/56f0a0a2Na0c86ea6.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t2620/166/2703833710/312660/531aa913/57709035N33857877.jpg!q70.jpg","num":1,"pid":33,"price":988,"pscid":2,"selected":1,"sellerid":10,"subhead":"三只松鼠零食特惠,专区满99减50,满199减100,火速抢购》","title":"三只松鼠 坚果炒货 零食奶油味 碧根果225g/袋"}],"sellerName":"商家10","sellerid":"10"},{"list":[{"bargainPrice":11800,"createtime":"2017-10-03T23:53:28","detailUrl":"https://mitem.jd.hk/ware/view.action?wareId=1988853309&cachekey=1acb07a701ece8d2434a6ae7fa6870a1","images":"https://m.360buyimg.com/n0/jfs/t6130/97/1370670410/180682/1109582a/593276b1Nd81fe723.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5815/178/2614671118/51656/7f52d137/593276c7N107b725a.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5878/60/2557817477/30873/4502b606/593276caN5a7d6357.jpg!q70.jpg","num":1,"pid":67,"price":14000,"pscid":40,"selected":1,"sellerid":11,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"},{"bargainPrice":22.9,"createtime":"2017-10-14T21:38:26","detailUrl":"https://item.m.jd.com/product/2542855.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t1930/284/2865629620/390243/e3ade9c4/56f0a08fNbd3a1235.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t2137/336/2802996626/155915/e5e90d7a/56f0a09cN33e01bd0.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t1882/31/2772215910/389956/c8dbf370/56f0a0a2Na0c86ea6.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t2620/166/2703833710/312660/531aa913/57709035N33857877.jpg!q70.jpg","num":1,"pid":34,"price":9,"pscid":2,"selected":0,"sellerid":11,"subhead":"三只松鼠零食特惠,专区满99减50,满199减100,火速抢购》","title":"三只松鼠 坚果炒货 零食奶油味 碧根果225g/袋"}],"sellerName":"商家11","sellerid":"11"}] */ private String msg; private String code; private List<DataBean> data; public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } public String getCode() { return code; } public void setCode(String code) { this.code = code; } public List<DataBean> getData() { return data; } public void setData(List<DataBean> data) { this.data = data; } public static class DataBean { /** * list : [{"bargainPrice":6666,"createtime":"2017-10-10T16:01:31","detailUrl":"https://item.m.jd.com/product/5089273.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t8284/363/1326459580/71585/6d3e8013/59b857f2N6ca75622.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t9346/182/1406837243/282106/68af5b54/59b8480aNe8af7f5c.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8434/54/1359766007/56140/579509d9/59b85801Nfea207db.jpg!q70.jpg","num":8,"pid":46,"price":234,"pscid":39,"selected":1,"sellerid":2,"subhead":"【iPhone新品上市】新一代iPhone,让智能看起来更不一样","title":"Apple iPhone 8 Plus (A1864) 64GB 金色 移动联通电信4G手机"}] * sellerName : 商家2 * sellerid : 2 */ private String sellerName; private String sellerid; private List<ListBean> list; private boolean checked; public boolean isChecked() { return checked; } public void setChecked(boolean checked) { this.checked = checked; } 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 : 6666.0 * createtime : 2017-10-10T16:01:31 * detailUrl : https://item.m.jd.com/product/5089273.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends * images : https://m.360buyimg.com/n0/jfs/t8284/363/1326459580/71585/6d3e8013/59b857f2N6ca75622.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t9346/182/1406837243/282106/68af5b54/59b8480aNe8af7f5c.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8434/54/1359766007/56140/579509d9/59b85801Nfea207db.jpg!q70.jpg * num : 8 * pid : 46 * price : 234.0 * pscid : 39 * selected : 1 * sellerid : 2 * subhead : 【iPhone新品上市】新一代iPhone,让智能看起来更不一样 * title : Apple iPhone 8 Plus (A1864) 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; 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; } } } }retrofit工具类:
public class RetrofitFactory { private static volatile RetrofitFactory instance; private ApiService apiService; public static OkHttpClient okHttpClient = new OkHttpClient.Builder() .connectTimeout(2000, TimeUnit.SECONDS) .readTimeout(2000, TimeUnit.SECONDS) .writeTimeout(2000, TimeUnit.SECONDS) .build(); public RetrofitFactory(String baseUrl) { //使我们能高度自定义转化器 //把 以前的 call 转化成 Observable,这是Retrofit与RxJava结合使用的关键 Retrofit retrofit = new Retrofit.Builder() .baseUrl(baseUrl) //使我们能高度自定义转化器 .addConverterFactory(ScalarsConverterFactory.create()) .client(okHttpClient) //把 以前的 call 转化成 Observable,这是Retrofit与RxJava结合使用的关键 .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .addConverterFactory(GsonConverterFactory.create()) .build(); apiService = retrofit.create(ApiService.class); } public static RetrofitFactory getInstance(String baseUrl){ if(instance==null){ synchronized (RetrofitFactory.class){ if(null==instance){ instance=new RetrofitFactory(baseUrl); } } } return instance; } public Observable<String> get(String url, Map<String, String> map) { return apiService.get(url, map) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()); } }接口:
public interface Shopinter1 { void success(ShopBean shopBean); }
shop p层:
public class Shoppresenter implements Shopinter1{ private final Shopmodel shopmodel; private final Shopinter2 shopinter2; public Shoppresenter(Shopinter2 shopinter2) { shopmodel = new Shopmodel(this); this.shopinter2=shopinter2; } public void getdata(String base3, Map<String, String> map) { shopmodel.getdata(base3,map); } @Override public void success(ShopBean shopBean) { shopinter2.success(shopBean); } }shop model:
public class Shopmodel { private final Shopinter1 shopinter1; public Shopmodel(Shopinter1 shopinter1) { this.shopinter1=shopinter1; } public void getdata(String base3, Map<String, String> map) { RetrofitFactory.getInstance(base3) .get("product/getCarts",map) .subscribe(new Observer<String>() { @Override public void onSubscribe(@NonNull Disposable d) { } @Override public void onNext(@NonNull String s) { if (s!=null){ ShopBean shopBean = new Gson().fromJson(s, ShopBean.class); shopinter1.success(shopBean); } } @Override public void onError(@NonNull Throwable e) { } @Override public void onComplete() { } }); } }shopactivity:
public class MainActivity extends AppCompatActivity implements View.OnClickListener,Shopinter2 { private CheckBox check_all; private TextView zongjia; private TextView zongshu; private List<ShopBean.DataBean> group; private List<List<ShopBean.DataBean.ListBean>> child; private ExpandableListView expanable_listview; private Shoppresenter shoppresenter; private Myadapter myadapter; private Handler handler = new Handler(){ @Override public void handleMessage(Message msg) { if (msg.what==0){ PriceBean priceBean = (PriceBean) msg.obj; zongjia.setText("总价:"+priceBean.getPrice()); zongshu.setText("结算("+priceBean.getCount()+")"); } } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initView(); getdata(); } private void getdata() { Map<String, String> map = new HashMap<>(); map.put("uid", "2792"); map.put("source", "android"); shoppresenter = new Shoppresenter(this); shoppresenter.getdata(Constant.Base3, map); } private void initView(){ check_all=(CheckBox)findViewById(R.id.check_all); check_all.setOnClickListener(this); zongjia=(TextView)findViewById(R.id.zongjia); zongshu=(TextView)findViewById(R.id.zongshu); expanable_listview = (ExpandableListView) findViewById(R.id.expanable_listview); } @Override public void success(ShopBean shopBean) { group = shopBean.getData(); child = new ArrayList<>(); if (group != null) { for (int i = 0; i < group.size(); i++) { List<ShopBean.DataBean.ListBean> list = group.get(i).getList(); child.add(list); } } //初始化看二级列表是否都选中,都选中一级列表页选中 for (int i = 0; i < group.size(); i++) { if (isAllChildInGroupSelected(i)) { group.get(i).setChecked(true); } } //如果所有一级列表都选中,全选按钮也选中 check_all.setChecked(isAllGroupChecked()); myadapter = new Myadapter( handler, MainActivity.this, group, child, shoppresenter); expanable_listview.setAdapter(myadapter); expanable_listview.setDividerHeight(5); //设置二级列表的箭头消失 expanable_listview.setGroupIndicator(null); //设置直接打开二级列表 for (int i = 0; i < group.size(); i++) { expanable_listview.expandGroup(i); } //初始化价格 myadapter.sendpriceandcount(); } private boolean isAllGroupChecked(){ for(int i=0;i<group.size();i++){ if(!group.get(i).isChecked()){//代表一级列表有没选中的 return false; } } return true; } //查看二级列表是否都选中,都选中返回true, private boolean isAllChildInGroupSelected(int groupPosition){ for(int i=0;i<group.get(groupPosition).getList().size();i++){ //只要有一个没选中就返回false if(group.get(groupPosition).getList().get(i).getSelected()==0){ return false; } } return true; } @Override public void onClick(View view) { } }适配器:
public class Myadapter extends BaseExpandableListAdapter { private Shoppresenter shoppresenter; private Handler handler; Context context; List<ShopBean.DataBean> group; List<List<ShopBean.DataBean.ListBean>>child; private int size; private int childi; private int allsize; private int a; public Myadapter( Handler handler, Context context, List<ShopBean.DataBean> group, List<List<ShopBean.DataBean.ListBean>> child,Shoppresenter shoppresenter) { this.handler = handler; this.context = context; this.group = group; this.child = child; this.shoppresenter =shoppresenter; } @Override public int getGroupCount() { return group.size(); } @Override public int getChildrenCount(int i) { return child.get(i).size(); } @Override public Object getGroup(int i) { return group.get(i); } @Override public Object getChild(int i, int i1) { return child.get(i).get(i1); } @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) { final holder1 h1; if (view==null){ h1= new holder1(); view = View.inflate(context, R.layout.yiji_layout, null); h1.check_group = view.findViewById(R.id.checkBox); h1.group_text = view.findViewById(R.id.group_text); view.setTag(h1); }else { h1 = (holder1) view.getTag(); } final ShopBean.DataBean dataBean = group.get(i); h1.check_group.setChecked(dataBean.isChecked()); h1.group_text.setText(dataBean.getSellerName()); h1.check_group.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { size = dataBean.getList().size(); childi = 0; updategroup(h1.check_group.isChecked(),dataBean); } }); return view; } private void updategroup(final boolean checked, final ShopBean.DataBean dataBean) { ShopBean.DataBean.ListBean listBean = dataBean.getList().get(childi); Map<String, String> params = new HashMap<>(); params.put("uid","2792"); params.put("sellerid", String.valueOf(listBean.getSellerid())); params.put("pid", String.valueOf(listBean.getPid())); params.put("selected", String.valueOf(listBean.getSelected()==0? 1:0)); params.put("num", String.valueOf(listBean.getNum())); RetrofitFactory.getInstance(Constant.Base4).get("product/updateCarts",params) .subscribe(new Observer<String>() { @Override public void onSubscribe(@NonNull Disposable d) { } @Override public void onNext(@NonNull String s) { childi++; if (childi<size){ updategroup(checked,dataBean); }else { Map<String, String> map = new HashMap<>(); map.put("uid", "2792"); map.put("source", "android"); shoppresenter.getdata(Constant.Baseurl, map); } } @Override public void onError(@NonNull Throwable e) { } @Override public void onComplete() { } }); } @Override public View getChildView(int i, int i1, boolean b, View view, ViewGroup viewGroup) { final holder2 h2; if (view==null){ h2=new holder2(); view=View.inflate(context,R.layout.erji_layout,null); h2.check_child = view.findViewById(R.id.child_check); h2.child_jia = view.findViewById(R.id.child_jia); h2.child_jian = view.findViewById(R.id.child_jian); h2.child_title = view.findViewById(R.id.child_title); h2.child_num = view.findViewById(R.id.child_num); h2.child_price = view.findViewById(R.id.child_price); h2.child_imageview = view.findViewById(R.id.child_imageview); h2.delete = view.findViewById(R.id.delete); h2.tshu = view.findViewById(R.id.tshu); h2.numlinear =view.findViewById(R.id.numlinear); view.setTag(h2); }else { h2 = (holder2) view.getTag(); } final ShopBean.DataBean.ListBean listBean = child.get(i).get(i1); String[] split = listBean.getImages().split("\\|"); Glide.with(context).load(split[0]).into(h2.child_imageview); h2.check_child.setChecked(listBean.getSelected()==0? false:true); h2.child_title.setText(listBean.getTitle()); h2.child_num.setText(listBean.getNum()+""); h2.child_price.setText("优惠价:¥"+listBean.getBargainPrice()); h2.delete.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //http://120.27.23.105/product/deleteCart?uid=72&pid=1 } }); h2.check_child.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { updatechilds(listBean); } }); h2.child_jia.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.d("tag","+++++++++++++++++点击了"); updatenumjia(listBean,true); } }); h2.child_jian.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (listBean.getNum()==1){ return; } updatenumjia(listBean,false); } }); return view; } private void updatechilds(ShopBean.DataBean.ListBean listBean) { //https://www.zhaoapi.cn/product/updateCarts?uid=71&sellerid=1&pid=1&selected=0&num=10 Map<String, String> params = new HashMap<>(); params.put("uid","2792"); params.put("sellerid", String.valueOf(listBean.getSellerid())); params.put("pid", String.valueOf(listBean.getPid())); params.put("selected", String.valueOf(listBean.getSelected()==0? 1:0)); params.put("num", String.valueOf(listBean.getNum())); RetrofitFactory.getInstance(Constant.Base4).get("product/updateCarts",params) .subscribe(new Observer<String>() { @Override public void onSubscribe(@NonNull Disposable d) { } @Override public void onNext(@NonNull String s) { Map<String, String> map = new HashMap<>(); map.put("uid", "2792"); map.put("source", "android"); shoppresenter.getdata(Constant.Baseurl, map); } @Override public void onError(@NonNull Throwable e) { } @Override public void onComplete() { } }); } private void updatenumjia(ShopBean.DataBean.ListBean listBean, boolean b) { int num = listBean.getNum(); //https://www.zhaoapi.cn/product/updateCarts?uid=71&sellerid=1&pid=1&selected=0&num=10 Map<String, String> params = new HashMap<>(); params.put("uid","2792"); params.put("sellerid", String.valueOf(listBean.getSellerid())); params.put("pid", String.valueOf(listBean.getPid())); params.put("selected", String.valueOf(listBean.getSelected())); if (b){ params.put("num", String.valueOf(num+1)); }else{ params.put("num", String.valueOf(num-1)); } RetrofitFactory.getInstance(Constant.Base4).get("product/updateCarts",params) .subscribe(new Observer<String>() { @Override public void onSubscribe(@NonNull Disposable d) { } @Override public void onNext(@NonNull String s) { Map<String, String> map = new HashMap<>(); map.put("uid", "2792"); map.put("source", "android"); shoppresenter.getdata(Constant.Baseurl, map); } @Override public void onError(@NonNull Throwable e) { } @Override public void onComplete() { } }); } public void delete(){ for (int i=0;i<group.size();i++){ ShopBean.DataBean dataBean = group.get(i); for (int j=0;j<dataBean.getList().size();j++){ if (child.get(i).get(j).getSelected()==1){ Map<String, String> params = new HashMap<>(); params.put("uid", "2792"); params.put("pid", String.valueOf(child.get(i).get(j).getPid())); RetrofitFactory.getInstance(Constant.Base4).get("product/updateCarts",params) .subscribe(new Observer<String>() { @Override public void onSubscribe(@NonNull Disposable d) { } @Override public void onNext(@NonNull String s) { Map<String, String> map = new HashMap<>(); map.put("uid", "2792"); map.put("source", "android"); shoppresenter.getdata(Constant.Baseurl, map); } @Override public void onError(@NonNull Throwable e) { } @Override public void onComplete() { } }); } } } } public void sendpriceandcount() { double price=0; int count=0; for (int i=0;i<group.size();i++){ ShopBean.DataBean dataBean = group.get(i); for (int j=0;j<dataBean.getList().size();j++){ if (child.get(i).get(j).getSelected()==1){ price+=child.get(i).get(j).getBargainPrice()*child.get(i).get(j).getNum(); count+=child.get(i).get(j).getNum(); } } } DecimalFormat decimalFormat = new DecimalFormat("#.00"); String price2 = decimalFormat.format(price); PriceBean priceBean = new PriceBean(price2, count); Message msg = Message.obtain(); msg.what=0; msg.obj=priceBean; handler.sendMessage(msg); } @Override public boolean isChildSelectable(int i, int i1) { return true; } public void setallchecked(boolean checked) { List<ShopBean.DataBean.ListBean>all = new ArrayList<>(); for (int i=0;i<group.size();i++){ for (int j=0;j<group.get(i).getList().size();j++){ all.add(group.get(i).getList().get(j)); } } allsize = all.size(); a = 0; updateallchecked(all,checked); } private void updateallchecked(final List<ShopBean.DataBean.ListBean> all, final boolean checked) { ShopBean.DataBean.ListBean listBean = all.get(a); Map<String, String> params = new HashMap<>(); params.put("uid","2792"); 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())); RetrofitFactory.getInstance(Constant.Base4).get("product/updateCarts",params) .subscribe(new Observer<String>() { @Override public void onSubscribe(@NonNull Disposable d) { } @Override public void onNext(@NonNull String s) { a++; if (a<allsize){ updateallchecked(all,checked); }else{ Map<String, String> map = new HashMap<>(); map.put("uid", "2792"); map.put("source", "android"); shoppresenter.getdata(Constant.Baseurl, map); } } @Override public void onError(@NonNull Throwable e) { } @Override public void onComplete() { } }); } class holder1{ CheckBox check_group; TextView group_text; } class holder2{ CheckBox check_child; TextView child_title; TextView child_price; TextView child_num; TextView child_jia; TextView child_jian; ImageView child_imageview; Button delete; LinearLayout numlinear; TextView tshu; } }