添加依赖
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile "io.reactivex.rxjava2:rxjava:2.1.1"
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
compile 'com.squareup.retrofit2:retrofit:2.3.0'
compile 'com.squareup.retrofit2:converter-gson:2.3.0'
compile 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
compile 'org.greenrobot:eventbus:3.1.1'
compile 'com.github.bumptech.glide:glide:3.7.0'
}
=========================
网络权限
<uses-permission android:name="android.permission.INTERNET"/>
============================
布局文件
activity_main.xml
xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="0dp"
android:orientation="vertical"
tools:context="bwie.com.day_shoping_1216.MainActivity">
<TextView
android:layout_gravity="center_horizontal"
android:textSize="30dp"
android:layout_marginTop="0dp"
android:gravity="center"
android:background="@color/colorPrimary"
android:textColor="#fff"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="购物车"
android:id="@+id/textView" />
<ExpandableListView
android:id="@+id/elv"
android:layout_weight="2"
android:layout_width="match_parent"
android:layout_height="match_parent">
ExpandableListView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<CheckBox
android:id="@+id/quanxuan"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="全选" />
<TextView
android:id="@+id/zongji"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="80dp"
android:text="合计:0" />
<TextView
android:id="@+id/heji"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="100dp"
android:background="@color/colorAccent"
android:gravity="center"
android:text="结算(0)" />
LinearLayout>
LinearLayout>
erji.xml
xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="30dp"
>
<CheckBox
android:layout_marginTop="20dp"
android:id="@+id/b_box"
android:layout_marginLeft="25dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:id="@+id/b_img"
/>
<LinearLayout
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:id="@+id/b_title"
android:layout_width="100dp"
android:layout_height="20dp"
android:layout_marginLeft="20dp" />
<TextView
android:layout_marginTop="10dp"
android:id="@+id/b_price"
android:textColor="#f00"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp" />
LinearLayout>
<LinearLayout
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical">
<TextView
android:id="@+id/b_jian"
android:layout_width="20dp"
android:layout_height="20dp"
android:text="-" />
<TextView
android:id="@+id/b_num"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:paddingBottom="2dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="2dp"
android:text="1" />
<TextView
android:id="@+id/b_jia"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginLeft="5dp"
android:text="+" />
<Button
android:id="@+id/b_del"
android:text="删除"
android:layout_marginLeft="30dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
LinearLayout>
LinearLayout>
yiji.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"
android:layout_marginTop="30dp"
android:orientation="horizontal">
<CheckBox
android:id="@+id/a_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/a_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:textSize="20dp"/>
LinearLayout>
===============================
ShoPingBean
package bwie.com.day_shoping_1216.bean;
import java.util.List;
/**
* Created by 迷人的脚毛!! on 2017/12/16.
*/
public class ShoPingBean {
/**
* msg : 请求成功
* code : 0
* data : [{"list":[],"sellerName":"","sellerid":"0"},{"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手机"}],"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":399,"createtime":"2017-10-02T15:20:02","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":2,"pid":81,"price":699,"pscid":85,"selected":0,"sellerid":2,"subhead":"满2件,总价打6.50折","title":"Gap男装 休闲舒适简约水洗五袋直筒长裤紧身牛仔裤941825 深灰色 33/32(175/84A)"}],"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":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":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":10,"pid":60,"price":13888,"pscid":40,"selected":0,"sellerid":4,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"}],"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手机 双卡双待"},{"bargainPrice":111.99,"createtime":"2017-10-03T23:43:53","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":3,"pid":12,"price":256,"pscid":1,"selected":0,"sellerid":5,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellerName":"商家5","sellerid":"5"},{"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":2,"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":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":3,"pid":100,"price":2200,"pscid":112,"selected":0,"sellerid":11,"subhead":"针织针织闪闪闪亮你的眼","title":"维迩旎 2017秋冬新款长袖针织连衣裙韩版气质中长款名媛包臀A字裙 zx179709 黑色 XL"}],"sellerName":"商家11","sellerid":"11"},{"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":23,"pid":71,"price":32999,"pscid":40,"selected":0,"sellerid":15,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"},{"bargainPrice":111.99,"createtime":"2017-10-14T21:48:08","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":3,"pid":22,"price":799,"pscid":1,"selected":0,"sellerid":15,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellerName":"商家15","sellerid":"15"},{"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":1,"pid":41,"price":456,"pscid":2,"selected":0,"sellerid":18,"subhead":"三只松鼠零食特惠,专区满99减50,满199减100,火速抢购》","title":"三只松鼠 坚果炒货 零食奶油味 碧根果225g/袋"}],"sellerName":"商家18","sellerid":"18"},{"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":5,"price":88.99,"pscid":1,"selected":0,"sellerid":21,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"},{"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":2,"pid":77,"price":38999.99,"pscid":40,"selected":0,"sellerid":21,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"}],"sellerName":"商家21","sellerid":"21"},{"list":[{"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":10,"pid":78,"price":999,"pscid":40,"selected":0,"sellerid":22,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"}],"sellerName":"商家22","sellerid":"22"}]
*/
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 : []
* sellerName :
* sellerid : 0
*/
private String sellerName;
private String sellerid;
private List<ListBean> list;
private boolean check;
public boolean isCheck() {
return check;
}
public void setCheck(boolean check) {
this.check = check;
}
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 {
private int price;
private String images;
private String title;
private boolean check;
private int cou=1;
public boolean isCheck() {
return check;
}
public void setCheck(boolean check) {
this.check = check;
}
public int getCou() {
return cou;
}
public void setCou(int cou) {
this.cou = cou;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public String getImages() {
return images;
}
public void setImages(String images) {
this.images = images;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
}
}
========================
MyAdpater
package bwie.com.day_shoping_1216.adpater;
import android.content.Context;
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 org.greenrobot.eventbus.EventBus;
import java.util.List;
import bwie.com.day_shoping_1216.CountPrice;
import bwie.com.day_shoping_1216.MessageEvent;
import bwie.com.day_shoping_1216.R;
import bwie.com.day_shoping_1216.bean.ShoPingBean;
/**
* Created by 迷人的脚毛!! on 2017/12/16.
*/
public class MyAdpater extends BaseExpandableListAdapter {
private Context context;
private List<ShoPingBean.DataBean> list;
private List<List<ShoPingBean.DataBean.ListBean>> data;
public MyAdpater(Context context, List<ShoPingBean.DataBean> list, List<List<ShoPingBean.DataBean.ListBean>> data) {
this.context = context;
this.list = list;
this.data = data;
}
@Override
public int getGroupCount() {
return list.size();
}
@Override
public int getChildrenCount(int i) {
return data.get(i).size();
}
@Override
public Object getGroup(int i) {
return list.get(i);
}
@Override
public Object getChild(int i, int i1) {
return data.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 false;
}
@Override
public View getGroupView(final int i, boolean b, View view, ViewGroup viewGroup) {
final ViewHolder1 viewHolder1;
if (view==null){
view = View.inflate(context, R.layout.yiji, null);
viewHolder1 = new ViewHolder1();
viewHolder1.name= view.findViewById(R.id.a_name);
viewHolder1.abox= view.findViewById(R.id.a_box);
view.setTag(viewHolder1);
}else{
viewHolder1=(ViewHolder1)view.getTag();
}
final ShoPingBean.DataBean dataBean = list.get(i);
String title = dataBean.getSellerName();
viewHolder1.abox.setChecked(dataBean.isCheck());
viewHolder1.name.setText(title);
//对一级的checkbox设置监听
viewHolder1.abox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//点击改变状态值
dataBean.setCheck(viewHolder1.abox.isChecked());
//通过一级的是否勾选,改变二级CheckBox状态
dataCheboxZT(i,viewHolder1.abox.isChecked());
EventBus.getDefault().post(jiSuan());
//通过判断是否全选,改变全选的状态
QuanxuangZT(listCheckboxQX());
notifyDataSetChanged();
}
});
return view;
}
@Override
public View getChildView(final int i, final int i1, boolean b, View view, ViewGroup viewGroup) {
final ViewHolder2 viewHolder2;
if (view==null){
view=View.inflate(context,R.layout.erji,null);
viewHolder2 = new ViewHolder2();
viewHolder2.title=view.findViewById(R.id.b_title);
viewHolder2.price=view.findViewById(R.id.b_price);
viewHolder2.bbox=view.findViewById(R.id.b_box);
viewHolder2.jia = view.findViewById(R.id.b_jia);
viewHolder2.jian = view.findViewById(R.id.b_jian);
viewHolder2.num = view.findViewById(R.id.b_num);
viewHolder2.del = view.findViewById(R.id.b_del);
viewHolder2.b_img = view.findViewById(R.id.b_img);
view.setTag(viewHolder2);
}else{
viewHolder2 = (ViewHolder2) view.getTag();
}
final ShoPingBean.DataBean.ListBean datasBean = data.get(i).get(i1);
String images = datasBean.getImages();
String[] s = images.split("\\|");
Glide.with(context).load(s[0]).into(viewHolder2.b_img);
viewHolder2.title.setText(datasBean.getTitle());
viewHolder2.price.setText(datasBean.getPrice()+"");
viewHolder2.bbox.setChecked(datasBean.isCheck());
//对二级里面的checkbox设置监听
viewHolder2.bbox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//二级的checkbox的点击时改变databean的属性
datasBean.setCheck(viewHolder2.bbox.isChecked());
//计算勾选状态下的价格和数量
EventBus.getDefault().post(jiSuan());
//判断二级的CheckBox是全选,改变一级的checkBox
listCheckboxZT(i,dataCheckboxZT(i));
//判断一级的checkbox是否选中,改变全选的状态值
QuanxuangZT(listCheckboxQX());
//刷新适配器
notifyDataSetChanged();
}
});
//减法的点击事件
viewHolder2.jian.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int num = datasBean.getCou();
if (num==1){
return;
}
//给控件赋值
viewHolder2.num.setText(--num+"");
//给控件赋值以后在赋值给控件本身
datasBean.setCou(num);
//当点击选中checkbox的时候
if (viewHolder2.bbox.isChecked()){
//进行计算赋值传递给主MainActivity进行显示
EventBus.getDefault().post(jiSuan());
}
notifyDataSetChanged();
}
});
//加的点击事件
viewHolder2.jia.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int num = datasBean.getCou();
++num;
//给控件赋值
viewHolder2.num.setText(num+"");
//当给控件赋值以后在赋值给控件本身
datasBean.setCou(num);
//当点击选中checkbox的时候
if (viewHolder2.bbox.isChecked()){
EventBus.getDefault().post(jiSuan());
}
notifyDataSetChanged();
}
});
//删除点击事件
viewHolder2.del.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
List<ShoPingBean.DataBean.ListBean> listBeen = data.get(i);
ShoPingBean.DataBean.ListBean remove = listBeen.remove(i1);
if (listBeen.size()==0){
data.remove(i);
list.remove(i);
}
EventBus.getDefault().post(jiSuan());
notifyDataSetChanged();
}
});
return view;
}
@Override
public boolean isChildSelectable(int i, int i1) {
return false;
}
class ViewHolder1{
CheckBox abox;
TextView name;
}
class ViewHolder2{
CheckBox bbox;
TextView title,price,time,num,jia,jian;
ImageView b_img;
Button del;
}
//改变一级checkbox 的状态
private void listCheckboxZT(int i,boolean flag){
ShoPingBean.DataBean dataBean = list.get(i);
dataBean.setCheck(flag);
}
//改变全选的状态
private void QuanxuangZT(boolean flag){
MessageEvent messageEvent = new MessageEvent();
messageEvent.setCheck(flag);
EventBus.getDefault().post(messageEvent);
}
/**
* 改变二级checkbox的状态
*/
private void dataCheboxZT(int i,boolean flag){
List<ShoPingBean.DataBean.ListBean> datasBeen = data.get(i);
for (int j = 0; j < datasBeen.size(); j++) {
datasBeen.get(j).setCheck(flag);
}
}
//判断一级的checkbox是否全部选中
private boolean listCheckboxQX(){
for (int i = 0; i <list.size() ; i++) {
ShoPingBean.DataBean dataBean = list.get(i);
List<ShoPingBean.DataBean.ListBean> lists = dataBean.getList();
for (int j = 0; j <lists.size() ; j++) {
ShoPingBean.DataBean.ListBean listBean = lists.get(j);
if (!listBean.isCheck()){
return false;
}
}
}
EventBus.getDefault().post(jiSuan());
return true;
}
//判断二级的checkbox是否全部选中
private boolean dataCheckboxZT(int i){
List<ShoPingBean.DataBean.ListBean> listBeen = data.get(i);
for (int j = 0; j <listBeen.size() ; j++) {
if (!listBeen.get(j).isCheck()){
return false;
}
}
return true;
}
//计算选中你时的价格和数量
private CountPrice jiSuan(){
int cout=0;
int price=0;
for (int i = 0; i <list.size() ; i++) {
ShoPingBean.DataBean dataBean = list.get(i);
List<ShoPingBean.DataBean.ListBean> lista = dataBean.getList();
for (int j = 0; j <lista.size() ; j++) {
ShoPingBean.DataBean.ListBean listBean = lista.get(j);
if (listBean.isCheck()){
cout+=listBean.getCou();
price+=listBean.getPrice()*listBean.getCou();
}
}
}
CountPrice countPrice = new CountPrice();
countPrice.setCount(cout);
countPrice.setPrice(price);
return countPrice;
}
/**
* 全选的时候改变所有的checkbox的状态
*/
public void checkALLStatus(boolean flag){
for (int i = 0; i <list.size() ; i++) {
ShoPingBean.DataBean dataBean = list.get(i);
dataBean.setCheck(flag);
List<ShoPingBean.DataBean.ListBean> datas = dataBean.getList();
for (int j = 0; j < datas.size(); j++) {
ShoPingBean.DataBean.ListBean datasBean = datas.get(j);
datasBean.setCheck(flag);
}
}
EventBus.getDefault().post(jiSuan());
notifyDataSetChanged();
}
}
===========================
ApiService
package bwie.com.day_shoping_1216.http;
import java.util.Map;
import bwie.com.day_shoping_1216.bean.ShoPingBean;
import io.reactivex.Flowable;
import retrofit2.http.GET;
import retrofit2.http.QueryMap;
/**
* Created by 迷人的脚毛!! on 2017/12/16.
*/
public interface ApiService {
//http://120.27.23.105/product/getCarts?uid=71
@GET("product/getCarts?")
Flowable<ShoPingBean> getData(@QueryMap Map<String,String> map);
}
======================
RetrofitUtil
package bwie.com.day_shoping_1216.http;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
/**
* Created by 迷人的脚毛!! on 2017/12/16.
*/
public class RetrofitUtil {
private static volatile RetrofitUtil instener;
private final ApiService apiService;
private RetrofitUtil() {
//http://120.27.23.105/product/getCarts?uid=71
Retrofit retrofit = new Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.baseUrl("http://120.27.23.105/")
.build();
apiService = retrofit.create(ApiService.class);
}
public static RetrofitUtil getInstener(){
if (null==instener){
synchronized (RetrofitUtil.class){
if (instener==null){
instener=new RetrofitUtil();
}
}
}
return instener;
}
public ApiService getApiService(){
return apiService;
}
}
==========================
modle层
DataModel
package bwie.com.day_shoping_1216.model;
import java.util.Map;
import bwie.com.day_shoping_1216.bean.ShoPingBean;
import bwie.com.day_shoping_1216.http.RetrofitUtil;
import bwie.com.day_shoping_1216.presenter.DataPresenter;
import io.reactivex.Flowable;
/**
* Created by 迷人的脚毛!! on 2017/12/16.
*/
public class DataModel implements IModel{
private DataPresenter presenter;
public DataModel(DataPresenter presenter) {
this.presenter = presenter;
}
@Override
public void getData(Map<String, String> map) {
Flowable<ShoPingBean> flowable = RetrofitUtil.getInstener().getApiService().getData(map);
presenter.getDatas(flowable);
}
}
IModel
package bwie.com.day_shoping_1216.model;
import java.util.Map;
/**
* Created by 迷人的脚毛!! on 2017/12/16.
*/
public interface IModel {
void getData(Map<String,String> map);
}
=========================
presenter层
DataPresenter
package bwie.com.day_shoping_1216.presenter;
import android.util.Log;
import java.util.List;
import java.util.Map;
import bwie.com.day_shoping_1216.bean.ShoPingBean;
import bwie.com.day_shoping_1216.model.DataModel;
import bwie.com.day_shoping_1216.model.IModel;
import bwie.com.day_shoping_1216.view.IView;
import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import io.reactivex.subscribers.DisposableSubscriber;
/**
* Created by 迷人的脚毛!! on 2017/12/16.
*/
public class DataPresenter implements IPresenter {
private IView iv;
private DisposableSubscriber<ShoPingBean> disposableSubscriber;
private static final String TAG = "DataPresenter";
public void attachView(IView iv){
this.iv=iv;
}
private void delete(){
if (iv!=null){
iv=null;
}
if (disposableSubscriber.isDisposed()){
disposableSubscriber.dispose();
}
}
@Override
public void getData(Map<String, String> map) {
IModel model= new DataModel(this);
model.getData(map);
}
public void getDatas(Flowable<ShoPingBean> flowable){
disposableSubscriber = flowable.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(new DisposableSubscriber<ShoPingBean>() {
@Override
public void onNext(ShoPingBean shoPingBean) {
if (shoPingBean!=null){
List<ShoPingBean.DataBean> data = shoPingBean.getData();
if (data!=null){
Log.i(TAG,"P层"+data.size());
iv.success(data);
}
}
}
@Override
public void onError(Throwable t) {
}
@Override
public void onComplete() {
}
});
}
}
IPresenter
package bwie.com.day_shoping_1216.presenter;
import java.util.Map;
/**
* Created by 迷人的脚毛!! on 2017/12/16.
*/
public interface IPresenter {
void getData(Map<String,String> map);
}
=======================
view层
IView
package bwie.com.day_shoping_1216.view;
/**
* Created by 迷人的脚毛!! on 2017/12/16.
*/
public interface IView {
void success(Object o);
void Failes(Exception e);
}
==========================
CountPrice
package bwie.com.day_shoping_1216;
/**
* Created by 迷人的脚毛!! on 2017/12/16.
*/
public class CountPrice {
private int count;
private int price;
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
}
==================
MainActivity
package bwie.com.day_shoping_1216;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ExpandableListView;
import android.widget.TextView;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import bwie.com.day_shoping_1216.adpater.MyAdpater;
import bwie.com.day_shoping_1216.bean.ShoPingBean;
import bwie.com.day_shoping_1216.presenter.DataPresenter;
import bwie.com.day_shoping_1216.view.IView;
public class MainActivity extends AppCompatActivity implements IView{
private CheckBox mQuanxuan;
private TextView zongjia;
private TextView heji;
private List<List<ShoPingBean.DataBean.ListBean>> data=new ArrayList<List<ShoPingBean.DataBean.ListBean>>();
private ExpandableListView elv;
private static final String TAG = "MainActivity";
private MyAdpater myAdpater;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
elv = (ExpandableListView) findViewById(R.id.elv);
mQuanxuan = (CheckBox) findViewById(R.id.quanxuan);
zongjia = (TextView) findViewById(R.id.zongji);
heji = (TextView) findViewById(R.id.heji);
HashMap<String,String> map = new HashMap<>();
map.put("uid","1290");
map.put("source","android");
DataPresenter dataPresenter = new DataPresenter();
dataPresenter.attachView(this);
dataPresenter.getData(map);
//注册EventBus
EventBus.getDefault().register(this);
mQuanxuan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//判断全选的状态
myAdpater.checkALLStatus(mQuanxuan.isChecked());
}
});
}
@Override
public void success(Object o) {
if (o instanceof List){
List<ShoPingBean.DataBean> news= (List<ShoPingBean.DataBean>) o;
if (news!=null){
Log.i(TAG,"主:"+news.size());
for (int i = 0; i <news.size() ; i++) {
ShoPingBean.DataBean dataBean = news.get(i);
List<ShoPingBean.DataBean.ListBean> list = dataBean.getList();
data.add(list);
}
//适配器
myAdpater = new MyAdpater(this, news, data);
//设置适配器
elv.setAdapter(myAdpater);
//将一级列表的展开标志隐藏
elv.setGroupIndicator(null);
//循环集合
for (int i = 0; i <news.size() ; i++) {
//将二级列表展开
elv.expandGroup(i);
}
}
}
}
@Override
public void Failes(Exception e) {
}
//接收适配器传过来的值
@Subscribe
public void onMessageEvent(MessageEvent event) {
//接收适配器(Myadpader)传递过来的值 ,将全选的状态设置为true或者false
mQuanxuan.setChecked(event.isCheck());
}
//接收适配器传过来的数量和总价
@Subscribe
public void onMessageEvent(CountPrice event) {
zongjia.setText("结算("+event.getCount()+")"+"");
heji.setText("总计:"+event.getPrice()+"");
}
@Override
protected void onDestroy() {
super.onDestroy();
EventBus.getDefault().unregister(this);
}
}
MessageEvent
package bwie.com.day_shoping_1216;
/**
* Created by 迷人的脚毛!! on 2017/12/16.
*/
public class MessageEvent{
private boolean check;
public boolean isCheck() {
return check;
}
public void setCheck(boolean check) {
this.check = check;
}
}