Retrofit&RxJava购物车

来源:互联网 发布:java的webservice 编辑:程序博客网 时间:2024/06/06 01:56
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 'io.reactivex.rxjava2:rxjava:2.1.7'compile 'io.reactivex.rxjava2:rxandroid:2.0.1'compile 'com.github.bumptech.glide:glide:3.7.0'
<uses-permission android:name="android.permission.INTERNET" />

drawable下的文件夹

back(左箭头)图片
edit.xml
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android">    <solid android:color="#FFFFFF" />    <!--<corners android:radius="3dip"/>-->    <stroke        android:width="1dip"        android:color="#BDC7D8" /></shape>

mipmap下的图片

baitiao dianpu jian jingdong lingdang normalheart shopcar


values下的文件夹

attrs.xml

<?xml version="1.0" encoding="utf-8"?><resources>    <declare-styleable name="AddDeleteViewStyle">        <attr name="left_text" format="string"></attr>        <attr name="right_text" format="string"></attr>        <attr name="middle_text" format="string"></attr>        <attr name="left_text_color" format="color"></attr>    </declare-styleable></resources>




layout布局

1.activity_main.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:orientation="vertical">    <!--头布局-->    <LinearLayout        android:id="@+id/top_bar"        android:layout_width="match_parent"        android:layout_height="48dp"        android:background="#f7f7f7"        android:orientation="vertical" >        <RelativeLayout            android:layout_width="match_parent"            android:layout_height="48dp"            android:background="@android:color/transparent"            android:orientation="vertical" >            <ImageView                android:id="@+id/back"                android:layout_width="48dp"                android:layout_height="48dp"                android:layout_alignParentLeft="true"                android:layout_gravity="center_vertical"                android:padding="12dp"                android:src="@drawable/back" />            <TextView                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:gravity="center"                android:minHeight="48dp"                android:text="购物车"                android:textColor="#1a1a1a"                android:textSize="16sp" />            <TextView                android:id="@+id/edit"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_alignParentRight="true"                android:layout_marginRight="40dp"                android:gravity="center"                android:minHeight="48dp"                android:text="编辑"                android:textColor="#1a1a1a"                android:textSize="14sp" />            <TextView                android:id="@+id/ok"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_alignParentRight="true"                android:layout_marginRight="40dp"                android:gravity="center"                android:minHeight="48dp"                android:text="完成"                android:textColor="#1a1a1a"                android:textSize="14sp"                android:visibility="gone"                />        </RelativeLayout>    </LinearLayout>    <ExpandableListView        android:id="@+id/exListView"        android:layout_width="match_parent"        android:layout_height="0dp"        android:layout_weight="1"        android:childIndicator="@null"        android:groupIndicator="@null" >    </ExpandableListView>    <LinearLayout        android:layout_width="match_parent"        android:layout_height="50dp"        android:gravity="center_vertical"        android:orientation="horizontal" >        <CheckBox            android:id="@+id/all_chekbox"            android:layout_marginLeft="20dp"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:checked="true"            />        <TextView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="全选"/>        <LinearLayout            android:id="@+id/ll_info"            android:layout_width="0dp"            android:layout_height="wrap_content"            android:layout_weight="4"            >            <LinearLayout                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:orientation="vertical"                android:layout_marginRight="20dp"                android:layout_weight="1"                >                <LinearLayout                    android:layout_width="match_parent"                    android:layout_height="wrap_content"                    android:orientation="horizontal"                    android:gravity="right"                    >                    <TextView                        android:layout_width="wrap_content"                        android:layout_height="wrap_content"                        android:layout_marginLeft="5dp"                        android:text="合计:"                        android:textSize="18sp"                        android:textStyle="bold" />                    <TextView                        android:id="@+id/total_price"                        android:layout_width="wrap_content"                        android:layout_height="wrap_content"                        android:text="0.00"                        android:textColor="#f23232"                        android:textSize="16sp"                        android:textStyle="bold" />                </LinearLayout>                <TextView                    android:id="@+id/total_number"                    android:layout_width="match_parent"                    android:layout_height="wrap_content"                    android:text="共有商品:0"                    android:gravity="right"                    android:textSize="16sp"                    android:textStyle="bold" />            </LinearLayout>            <TextView                android:id="@+id/tv_go_to_pay"                android:layout_width="match_parent"                android:layout_height="match_parent"                android:layout_weight="3"                android:background="#fd7a05"                android:clickable="true"                android:gravity="center"                android:text="结算"                android:textColor="#FAFAFA"                />            <Button                android:id="@+id/delete_all"                android:layout_width="match_parent"                android:layout_height="match_parent"                android:layout_weight="3"                android:background="#e7280e"                android:clickable="true"                android:gravity="center"                android:text="删除"                android:textColor="#FAFAFA"                android:visibility="gone"                />        </LinearLayout>    </LinearLayout></LinearLayout>

2.activity_xiang_qing.xml(这是详情 Activity的布局)

<?xml version="1.0" encoding="utf-8"?><LinearLayout    android:orientation="vertical"    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.bwei.goshopping.view.XiangQingActivity"    >    <LinearLayout        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:orientation="horizontal"        android:id="@+id/lei_xiangll"        >        <ImageView            android:layout_width="30dp"            android:layout_height="30dp"            android:background="@mipmap/jian"            android:id="@+id/lei_xiangback"            />        <TextView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="商品"            android:layout_weight="1"            android:layout_marginLeft="30dp"            android:layout_marginTop="10dp"            android:textColor="#ff00"            />        <TextView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="详情"            android:layout_weight="1"            android:layout_marginTop="10dp"            />        <TextView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="评价"            android:layout_weight="1"            android:layout_marginTop="10dp"            />    </LinearLayout>    <TextView        android:layout_width="match_parent"        android:layout_height="1dp"        android:background="#7e7f7c79"        android:id="@+id/ttttt"        />    <LinearLayout        android:id="@+id/lei_xiangrlv"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_weight="1"        android:orientation="vertical">        <ImageView            android:id="@+id/lei_xiangimg"            android:layout_width="match_parent"            android:layout_height="350dp"            android:layout_weight="1" />        <LinearLayout            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:orientation="horizontal"            >            <ImageView                android:layout_width="70dp"                android:layout_height="30dp"                android:background="@mipmap/jingdong"                />            <TextView                android:id="@+id/lei_xiangname"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                />        </LinearLayout>        <TextView            android:id="@+id/lei_xiangprice"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:textColor="#ff00"            android:textSize="30dp"            />    </LinearLayout>    <ImageView        android:layout_width="match_parent"        android:layout_height="5dp"        android:background="@mipmap/baitiao"        android:layout_weight="1"        />    <TextView        android:id="@+id/ttttt2"        android:layout_width="match_parent"        android:layout_height="8dp"        android:background="#7ebebcba" />    <LinearLayout        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:orientation="horizontal"        >        <LinearLayout            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:orientation="vertical"            android:layout_gravity="center"            android:layout_marginLeft="10dp"            android:layout_weight="1"            >            <ImageView                android:layout_width="20dp"                android:layout_height="20dp"                android:background="@mipmap/lingdang"                android:layout_gravity="center"                />            <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="供应商"                android:textSize="10dp"                android:layout_gravity="center"                />        </LinearLayout>        <LinearLayout            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:orientation="vertical"            android:layout_gravity="center"            android:layout_marginLeft="10dp"            android:layout_weight="1"            >            <ImageView                android:layout_width="20dp"                android:layout_height="20dp"                android:background="@mipmap/dianpu"                android:layout_gravity="center"                />            <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="店铺"                android:textSize="10dp"                android:layout_gravity="center"                />        </LinearLayout>        <LinearLayout            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:orientation="vertical"            android:layout_gravity="center"            android:layout_marginLeft="10dp"            android:layout_weight="1"            >            <ImageView                android:layout_width="20dp"                android:layout_height="20dp"                android:background="@mipmap/normalheart"                android:layout_gravity="center"                />            <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="关注"                android:textSize="10dp"                android:layout_gravity="center"                />        </LinearLayout>        <LinearLayout            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:orientation="vertical"            android:layout_gravity="center"            android:layout_marginLeft="10dp"            android:layout_weight="1"            >            <ImageView                android:layout_width="20dp"                android:layout_height="20dp"                android:background="@mipmap/shopcar"                android:layout_gravity="center"                />            <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="购物车"                android:textSize="10dp"                android:layout_gravity="center"                />        </LinearLayout>        <Button            android:id="@+id/lei_xiangbutton"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:background="#fad353"            android:text="加入购物车"            android:textColor="#f9f4f4"            />        <Button            android:id="@+id/lei_xiangbutton2"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:background="#ff00"            android:text="立即购买"            android:textColor="#f9f4f4"            />    </LinearLayout></LinearLayout>


3.ex_child_item.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:descendantFocusability="blocksDescendants"    xmlns:app="http://schemas.android.com/apk/res-auto"    android:layout_width="match_parent"    android:layout_height="230dp"    android:orientation="horizontal">    <CheckBox        android:id="@+id/child_checkbox"        android:layout_marginTop="50dp"        android:layout_marginLeft="20dp"        android:layout_marginBottom="50dp"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        />    <RelativeLayout        android:layout_marginLeft="20dp"        android:layout_width="match_parent"        android:layout_height="match_parent">        <TextView            android:id="@+id/shop_title"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_alignParentLeft="true"            android:layout_alignParentStart="true"            android:layout_marginLeft="17dp"            android:layout_marginStart="17dp"            android:text="TextView"            android:layout_alignParentTop="true" />        <ImageView            android:id="@+id/shop_img"            android:layout_width="90dp"            android:layout_height="90dp"            android:layout_marginTop="30dp"            app:srcCompat="@mipmap/ic_launcher"            android:layout_below="@+id/shop_name"            android:layout_alignParentLeft="true"            android:layout_alignParentStart="true" />        <TextView            android:id="@+id/shop_price"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_alignTop="@+id/shop_img"            android:layout_centerHorizontal="true"            android:layout_marginTop="10dp"            android:text="20"            android:textColor="#f23232"/>        <com.bwei.goshopping.view.AddDeleteView            android:id="@+id/adv"            android:layout_width="160dp"            android:layout_height="30dp"            android:layout_below="@+id/shop_price"            android:layout_marginTop="30dp"            android:layout_marginLeft="140dp"            app:left_text="-"            app:right_text="+"            app:middle_text="1"            android:focusable="false"/>        <Button            android:id="@+id/shop_delete"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_alignParentEnd="true"            android:layout_alignParentRight="true"            android:layout_centerVertical="true"            android:text="删除" />    </RelativeLayout></LinearLayout>


4.ex_group_item.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:background="#cfc3c3"    android:orientation="horizontal">    <CheckBox        android:id="@+id/group_checkbox"        android:layout_marginLeft="20dp"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:focusable="false"/>    <TextView        android:id="@+id/shop_name"        android:layout_marginLeft="20dp"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:textSize="16dp" /></LinearLayout>

5.layout_add_delete.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:orientation="horizontal"    android:weightSum="1">    <TextView        android:id="@+id/txt_delete"        android:layout_width="30dp"        android:layout_height="30dp"        android:text="-"        android:gravity="center"        android:background="#8b948b"/>    <EditText        android:id="@+id/et_number"        android:layout_marginTop="2dp"        android:layout_width="50dp"        android:layout_height="30dp"        android:background="@drawable/edit"        android:layout_weight="0.00"        android:gravity="center"        android:text="1"/>    <TextView        android:id="@+id/txt_add"        android:layout_width="30dp"        android:layout_height="30dp"        android:text="+"        android:gravity="center"        android:background="#8b948b"/></LinearLayout>


http包

ApiService接口

import com.bwei.goshopping.bean.AddBean;import com.bwei.goshopping.bean.DeleteBean;import com.bwei.goshopping.bean.GoodsBean;import com.bwei.goshopping.bean.XBeans;import java.util.Map;import io.reactivex.Flowable;import retrofit2.http.GET;import retrofit2.http.QueryMap;/** * Created by HQ on 2017/12/15. */public interface ApiService {    @GET("product/getCarts")    Flowable<GoodsBean> getHeqi(@QueryMap Map<String, String> map);    @GET("product/deleteCart")    Flowable<DeleteBean> getdelete(@QueryMap Map<String, String> map);    @GET("product/getProductDetail")    Flowable<XBeans> getx(@QueryMap Map<String, String> map);    @GET("product/addCart")    Flowable<AddBean> getadd(@QueryMap Map<String, String> map);}RetrofitUtils工具类
import retrofit2.Retrofit;import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;import retrofit2.converter.gson.GsonConverterFactory;public class RetrofitUtils {    private static volatile RetrofitUtils instance;    private ApiService apiService;    private RetrofitUtils() {        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 RetrofitUtils getInstance() {        if (instance == null) {            synchronized (RetrofitUtils.class) {                if (null == instance) {                    instance = new RetrofitUtils();                }            }        }        return instance;    }    public ApiService getApiService() {        return apiService;    }}

 
bean包

GoodsBean类

import java.util.List;/** * Created by HQ on 2017/12/19. */public class GoodsBean {    /**     * msg : 请求成功     * code : 0     * data : [{"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":3,"pid":80,"price":777,"pscid":40,"selected":0,"sellerid":1,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP213英寸Bar i5/8G/256G"},{"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":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":24,"price":288,"pscid":2,"selected":0,"sellerid":1,"subhead":"三只松鼠零食特惠,专区满9950,满199100,火速抢购》","title":"三只松鼠 坚果炒货 零食奶油味 碧根果225g/"}],"sellerName":"商家1","sellerid":"1"},{"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":1,"pid":46,"price":234,"pscid":39,"selected":0,"sellerid":2,"subhead":"iPhone新品上市】新一代iPhone,让智能看起来更不一样","title":"Apple iPhone 8 Plus (A1864) 64GB 金色 移动联通电信4G手机"},{"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":25,"price":399,"pscid":2,"selected":0,"sellerid":2,"subhead":"三只松鼠零食特惠,专区满9950,满199100,火速抢购》","title":"三只松鼠 坚果炒货 零食奶油味 碧根果225g/"}],"sellerName":"商家2","sellerid":"2"},{"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":48,"price":222,"pscid":39,"selected":0,"sellerid":4,"subhead":"【现货新品抢购】全面屏2.0震撼来袭,骁龙835处理器,四曲面陶瓷机","title":"小米(MI) 小米MIX2 手机 黑色 全网通 (6GB+64GB)【标配版】"}],"sellerName":"商家4","sellerid":"4"},{"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"},{"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":2,"price":299,"pscid":1,"selected":0,"sellerid":18,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"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"}],"sellerName":"商家21","sellerid":"21"}]     */    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":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":3,"pid":80,"price":777,"pscid":40,"selected":0,"sellerid":1,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP213英寸Bar i5/8G/256G"},{"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":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":24,"price":288,"pscid":2,"selected":0,"sellerid":1,"subhead":"三只松鼠零食特惠,专区满9950,满199100,火速抢购》","title":"三只松鼠 坚果炒货 零食奶油味 碧根果225g/"}]         * sellerName : 商家1         * sellerid : 1         */        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 : 11800.0             * 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 : 3             * pid : 80             * price : 777.0             * pscid : 40             * selected : 0             * sellerid : 1             * subhead : 购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)             * title : 全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP213英寸Bar i5/8G/256G             */            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;            }        }    }}

GoodsGroup

public class GoodsGroup {    private boolean checkbox;    private String grouptitle;    public GoodsGroup(boolean checkbox, String grouptitle) {        this.checkbox = checkbox;        this.grouptitle = grouptitle;    }    public boolean isCheckbox() {        return checkbox;    }    public void setCheckbox(boolean checkbox) {        this.checkbox = checkbox;    }    public String getGrouptitle() {        return grouptitle;    }    public void setGrouptitle(String grouptitle) {        this.grouptitle = grouptitle;    }    @Override    public String toString() {        return "GoodsGroup{" +                "checkbox=" + checkbox +                ", grouptitle='" + grouptitle + '\'' +                '}';    }}


GoodsChilde类

public class GoodsChilde {    private String childTitle;    private boolean checkchild;    private String img;    private double price;    private int num;    private boolean btn;    private int pid;    private String shul;    public GoodsChilde(String childTitle, boolean checkchild, String img, double price, int num, boolean btn, int pid, String shul) {        this.childTitle = childTitle;        this.checkchild = checkchild;        this.img = img;        this.price = price;        this.num = num;        this.btn = btn;        this.pid = pid;        this.shul = shul;    }    public String getChildTitle() {        return childTitle;    }    public void setChildTitle(String childTitle) {        this.childTitle = childTitle;    }    public boolean isCheckchild() {        return checkchild;    }    public void setCheckchild(boolean checkchild) {        this.checkchild = checkchild;    }    public String getImg() {        return img;    }    public void setImg(String img) {        this.img = img;    }    public double getPrice() {        return price;    }    public void setPrice(double price) {        this.price = price;    }    public int getNum() {        return num;    }    public void setNum(int num) {        this.num = num;    }    public boolean isBtn() {        return btn;    }    public void setBtn(boolean btn) {        this.btn = btn;    }    public int getPid() {        return pid;    }    public void setPid(int pid) {        this.pid = pid;    }    public String getShul() {        return shul;    }    public void setShul(String shul) {        this.shul = shul;    }}


DeleteBean类

public class DeleteBean {    /**     * msg : 购物车删除成功!     * code : 0     */    private String msg;    private String code;    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;    }}

XBeans类


public class XBeans {    /**     * msg :     * seller : {"description":"我是商家17","icon":"http://120.27.23.105/images/icon.png","name":"商家17","productNums":999,"score":5,"sellerid":17}     * code : 0     * data : {"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","itemtype":1,"pid":1,"price":118,"pscid":1,"salenum":0,"sellerid":17,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}     */    private String msg;    private SellerBean seller;    private String code;    private DataBean data;    public String getMsg() {        return msg;    }    public void setMsg(String msg) {        this.msg = msg;    }    public SellerBean getSeller() {        return seller;    }    public void setSeller(SellerBean seller) {        this.seller = seller;    }    public String getCode() {        return code;    }    public void setCode(String code) {        this.code = code;    }    public DataBean getData() {        return data;    }    public void setData(DataBean data) {        this.data = data;    }    public static class SellerBean {        /**         * description : 我是商家17         * icon : http://120.27.23.105/images/icon.png         * name : 商家17         * productNums : 999         * score : 5.0         * sellerid : 17         */        private String description;        private String icon;        private String name;        private int productNums;        private double score;        private int sellerid;        public String getDescription() {            return description;        }        public void setDescription(String description) {            this.description = description;        }        public String getIcon() {            return icon;        }        public void setIcon(String icon) {            this.icon = icon;        }        public String getName() {            return name;        }        public void setName(String name) {            this.name = name;        }        public int getProductNums() {            return productNums;        }        public void setProductNums(int productNums) {            this.productNums = productNums;        }        public double getScore() {            return score;        }        public void setScore(double score) {            this.score = score;        }        public int getSellerid() {            return sellerid;        }        public void setSellerid(int sellerid) {            this.sellerid = sellerid;        }    }    public static class DataBean {        /**         * 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         * itemtype : 1         * pid : 1         * price : 118.0         * pscid : 1         * salenum : 0         * sellerid : 17         * subhead : 每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下         * title : 北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g         */        private double bargainPrice;        private String createtime;        private String detailUrl;        private String images;        private int itemtype;        private int pid;        private double price;        private int pscid;        private int salenum;        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 getItemtype() {            return itemtype;        }        public void setItemtype(int itemtype) {            this.itemtype = itemtype;        }        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 getSalenum() {            return salenum;        }        public void setSalenum(int salenum) {            this.salenum = salenum;        }        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;        }    }}


AddBean类

public class AddBean {    /**     * msg : 加购成功     * code : 0     */    private String msg;    private String code;    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;    }}

model包

IModel接口

public interface IModel {    void getData(HashMap<String, String> map);}


NewsModel类

mport android.util.Log;import com.bwei.goshopping.bean.GoodsBean;import com.bwei.goshopping.http.RetrofitUtils;import com.bwei.goshopping.presenter.PresenterTwo;import java.util.HashMap;import io.reactivex.Flowable;/** * Created by HQ on 2017/12/7. *///网络请求public class NewsModel implements IModel {    private PresenterTwo presenter;    public NewsModel(PresenterTwo presenter) {        this.presenter = presenter;    }    @Override    public void getData(HashMap<String,String> map) {        Flowable<GoodsBean> flowable = RetrofitUtils.getInstance().getApiService().getHeqi(map);        Log.i("fff",flowable+"");        presenter.getNews(flowable);    }}

DModel接口

public interface DModel {    void getDelete(HashMap<String, String> map);}
DeleteModel类

import android.util.Log;import com.bwei.goshopping.bean.DeleteBean;import com.bwei.goshopping.http.RetrofitUtils;import com.bwei.goshopping.presenter.DeletePresenter;import java.util.HashMap;import io.reactivex.Flowable;/** * Created by HQ on 2017/12/7. *///网络请求public class DeleteModel implements DModel {    private DeletePresenter deletePresenter;    public DeleteModel(DeletePresenter deletePresenter) {        this.deletePresenter = deletePresenter;    }    @Override    public void getDelete(HashMap<String, String> map) {        Flowable<DeleteBean> getdelete = RetrofitUtils.getInstance().getApiService().getdelete(map);        Log.i("fff",getdelete+"");        deletePresenter.getNews(getdelete);    }}


XModels接口

public interface XModels {    void getDelete(HashMap<String, String> map);}XModel类 
import android.util.Log;import com.bwei.goshopping.bean.XBeans;import com.bwei.goshopping.http.RetrofitUtils;import com.bwei.goshopping.presenter.XPresenter;import java.util.HashMap;import io.reactivex.Flowable;/** * Created by HQ on 2017/12/7. *///网络请求public class XModel implements XModels {    private XPresenter xPresenter;    public XModel(XPresenter xPresenter ) {        this.xPresenter = xPresenter;    }    @Override    public void getDelete(HashMap<String, String> map) {        Flowable<XBeans> getdelete = RetrofitUtils.getInstance().getApiService().getx(map);        Log.i("fff",getdelete+"");        xPresenter.getNews(getdelete);    }}


AddModel接口

public interface AddModel {    void getAdd(HashMap<String, String> map);}


AddModels类

import android.util.Log;import com.bwei.goshopping.bean.AddBean;import com.bwei.goshopping.http.RetrofitUtils;import com.bwei.goshopping.presenter.AddPresenter;import java.util.HashMap;import io.reactivex.Flowable;/** * Created by HQ on 2017/12/7. *///网络请求public class AddModels implements AddModel {    private AddPresenter addPresenter;    public AddModels(AddPresenter addPresenter) {        this.addPresenter = addPresenter;    }    @Override    public void getAdd(HashMap<String, String> map) {        Flowable<AddBean> getadd = RetrofitUtils.getInstance().getApiService().getadd(map);        Log.i("fff",getadd+"");        addPresenter.getadd(getadd);    }}


presenter包

BasePresenter接口

public interface BasePresenter {    void getData(HashMap<String, String> map);}PresenterTwo类
import android.util.Log;import com.bwei.goshopping.bean.GoodsBean;import com.bwei.goshopping.bean.GoodsChilde;import com.bwei.goshopping.bean.GoodsGroup;import com.bwei.goshopping.model.NewsModel;import com.bwei.goshopping.view.GoodsViews;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import io.reactivex.Flowable;import io.reactivex.android.schedulers.AndroidSchedulers;import io.reactivex.schedulers.Schedulers;import io.reactivex.subscribers.DisposableSubscriber;/** * Created by WuXirui * Create Time: 2017/12/6 * Description: */public class PresenterTwo implements BasePresenter {    private GoodsViews iv;    private DisposableSubscriber<GoodsBean> subscriber;    private List<GoodsGroup> list;//给父级的集合不new出来、    private List<List<GoodsChilde>> list2;//给子级的集合    public PresenterTwo(GoodsViews iv, List<GoodsGroup> list, List<List<GoodsChilde>> list2) {        this.iv = iv;        this.list = list;        this.list2 = list2;    }    public void attachView(GoodsViews iv) {        this.iv = iv;    }    public void detachView() {        if (iv != null) {            iv = null;        }        if (subscriber != null) {            if (!subscriber.isDisposed()) {                subscriber.dispose();            }        }    }    @Override    public void getData(HashMap<String,String> map) {        NewsModel model = new NewsModel(this);        model.getData(map);    }    public void getNews(Flowable<GoodsBean> flowable) {        subscriber = flowable.subscribeOn(Schedulers.io())                .observeOn(AndroidSchedulers.mainThread())                .subscribeWith(new DisposableSubscriber<GoodsBean>() {                    @Override                    public void onNext(GoodsBean listMessageBean) {                        Log.i("aaa", listMessageBean + "");                        if(listMessageBean!=null){                            List<GoodsBean.DataBean> data = listMessageBean.getData();                            Log.e("ddd",data+"");                            if(data!=null){                                for (int i=0;i<data.size();i++){                                    String sellerName = data.get(i).getSellerName();                                    list.add(new GoodsGroup(true,sellerName));                                    //解析子集集合                                    List<GoodsBean.DataBean.ListBean> lists = data.get(i).getList();                                    //因为集合里面套集合,要放一个集合,所以新new一个集合,是子集                                    List<GoodsChilde> list1=new ArrayList<GoodsChilde>();                                    for (int j=0;j<lists.size();j++){                                        String title = lists.get(j).getTitle();                                        String images = lists.get(j).getImages();                                        double price = lists.get(j).getBargainPrice();                                        int pid = lists.get(j).getPid();                                        int num = lists.get(j).getNum();                                        list1.add(new GoodsChilde(title,true,images,price,1,true,pid,num+""));                                    }                                    list2.add(list1);                                    Log.e("hhh", list2.toString());                                }                                //通过新建的view接口,传给mainActivity                                iv.onSuccess(list,list2);                            }                        }else{                            Log.e("iii", "===============没有东西!!!===============");                        }                    }                    @Override                    public void onError(Throwable t) {                        iv.onFiled(new Exception(t));                    }                    @Override                    public void onComplete() {                    }                });    }}
DPost接口
public interface DPost {    void getData(HashMap<String, String> map);}

DeletePresenter类

import android.util.Log;import com.bwei.goshopping.bean.DeleteBean;import com.bwei.goshopping.model.DeleteModel;import com.bwei.goshopping.view.DeleteViews;import com.bwei.goshopping.view.GoodsViews;import java.util.HashMap;import io.reactivex.Flowable;import io.reactivex.android.schedulers.AndroidSchedulers;import io.reactivex.schedulers.Schedulers;import io.reactivex.subscribers.DisposableSubscriber;/** * Created by WuXirui * Create Time: 2017/12/6 * Description: */public class DeletePresenter implements DPost {    private DeleteViews deleteViews;    private DisposableSubscriber<DeleteBean> subscriber;    public DeletePresenter(DeleteViews deleteViews) {        this.deleteViews = deleteViews;    }    public void attachView(GoodsViews iv) {        this.deleteViews = deleteViews;    }    public void detachView() {        if (deleteViews != null) {            deleteViews = null;        }        if (subscriber != null) {            if (!subscriber.isDisposed()) {                subscriber.dispose();            }        }    }    @Override    public void getData(HashMap<String,String> map) {        DeleteModel model = new DeleteModel(this);        model.getDelete(map);    }    public void getNews(Flowable< DeleteBean> flowable) {        subscriber = flowable.subscribeOn(Schedulers.io())                .observeOn(AndroidSchedulers.mainThread())                .subscribeWith(new DisposableSubscriber< DeleteBean>() {                    @Override                    public void onNext( DeleteBean listMessageBean) {                        Log.i("aaa", listMessageBean + "");                        if(listMessageBean!=null){                                //通过新建的view接口,传给mainActivity                            deleteViews.onDSuccess(listMessageBean);                        }else{                            Log.e("iii", "===============没有东西!!!===============");                        }                    }                    @Override                    public void onError(Throwable t) {                        deleteViews.onDFiled(new Exception(t));                    }                    @Override                    public void onComplete() {                    }                });    }}XPost接口 
public interface XPost {    void getData(HashMap<String, String> map);}XPresenter类

import android.util.Log;import com.bwei.goshopping.bean.XBeans;import com.bwei.goshopping.model.XModel;import com.bwei.goshopping.view.XViews;import java.util.HashMap;import io.reactivex.Flowable;import io.reactivex.android.schedulers.AndroidSchedulers;import io.reactivex.schedulers.Schedulers;import io.reactivex.subscribers.DisposableSubscriber;/** * Created by WuXirui * Create Time: 2017/12/6 * Description: */public class XPresenter implements XPost {    private XViews xViews;    private DisposableSubscriber<XBeans> subscriber;    public XPresenter(XViews xViews) {        this.xViews = xViews;    }    public void attachView(XViews xViews) {        this.xViews = xViews;    }    public void detachView() {        if (xViews != null) {            xViews = null;        }        if (subscriber != null) {            if (!subscriber.isDisposed()) {                subscriber.dispose();            }        }    }    @Override    public void getData(HashMap<String,String> map) {        XModel model = new XModel(this);        model.getDelete(map);    }    public void getNews(Flowable<XBeans> flowable) {        subscriber = flowable.subscribeOn(Schedulers.io())                .observeOn(AndroidSchedulers.mainThread())                .subscribeWith(new DisposableSubscriber< XBeans>() {                    @Override                    public void onNext( XBeans listMessageBean) {                        if(listMessageBean!=null){                            xViews.onDSuccess(listMessageBean);                        }else{                            Log.e("iii", "===============没有东西!!!===============");                        }                    }                    @Override                    public void onError(Throwable t) {                        xViews.onDFiled(new Exception(t));                    }                    @Override                    public void onComplete() {                    }                });    }}AddPost接口 
public interface AddPost {    void getData(HashMap<String, String> map);}


AddPresenter类

import android.util.Log;import com.bwei.goshopping.bean.AddBean;import com.bwei.goshopping.model.AddModels;import com.bwei.goshopping.view.AddViews;import java.util.HashMap;import io.reactivex.Flowable;import io.reactivex.android.schedulers.AndroidSchedulers;import io.reactivex.schedulers.Schedulers;import io.reactivex.subscribers.DisposableSubscriber;/** * Created by WuXirui * Create Time: 2017/12/6 * Description: */public class AddPresenter implements AddPost {    private AddViews addViews;    private DisposableSubscriber<AddBean> subscriber;    public AddPresenter(AddViews addViews) {        this.addViews = addViews;    }    public void attachView(AddViews addViews) {        this.addViews = addViews;    }    public void detachView() {        if (addViews != null) {            addViews = null;        }        if (subscriber != null) {            if (!subscriber.isDisposed()) {                subscriber.dispose();            }        }    }    @Override    public void getData(HashMap<String,String> map) {        AddModels model = new AddModels(this);        model.getAdd(map);    }    public void getadd(Flowable<AddBean> flowable) {        subscriber = flowable.subscribeOn(Schedulers.io())                .observeOn(AndroidSchedulers.mainThread())                .subscribeWith(new DisposableSubscriber< AddBean>() {                    @Override                    public void onNext( AddBean listMessageBean) {                        Log.i("aaa", listMessageBean + "");                        if(listMessageBean!=null){                                //通过新建的view接口,传给mainActivity                            addViews.onASuccess(listMessageBean);                        }else{                            Log.e("iii", "===============没有东西!!!===============");                        }                    }                    @Override                    public void onError(Throwable t) {                        addViews.onAFiled(new Exception(t));                    }                    @Override                    public void onComplete() {                    }                });    }}view包 
GoodsViews接口

import com.bwei.goshopping.bean.GoodsChilde;import com.bwei.goshopping.bean.GoodsGroup;import java.util.List;/** * Created by HQ on 2017/11/21. */public interface GoodsViews {    void onSuccess(List<GoodsGroup> list, List<List<GoodsChilde>> list2);    void onFiled( Exception e);}DeleteViews接口 
public interface DeleteViews {    void onDSuccess(Object o);    void onDFiled(Exception e);}XViews接口 
public interface XViews {    void onDSuccess(Object o);    void onDFiled(Exception e);}


DeleteViews接口

public interface DeleteViews {    void onDSuccess(Object o);    void onDFiled(Exception e);}


XiangQingActivity类

import android.content.Intent;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.util.Log;import android.view.View;import android.widget.Button;import android.widget.ImageView;import android.widget.TextView;import android.widget.Toast;import com.bumptech.glide.Glide;import com.bwei.goshopping.R;import com.bwei.goshopping.bean.AddBean;import com.bwei.goshopping.bean.XBeans;import com.bwei.goshopping.presenter.AddPresenter;import com.bwei.goshopping.presenter.XPresenter;import java.util.HashMap;public class XiangQingActivity extends AppCompatActivity implements XViews,AddViews {    private ImageView img;    private TextView name;    private ImageView lei_xiangback;    private Button lei_xiangbutton;    private TextView prices;    private XPresenter two;    private AddPresenter addPresenter;    private String pid;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_xiang_qing);        img = (ImageView) findViewById(R.id.lei_xiangimg);        prices = (TextView) findViewById(R.id.lei_xiangprice);        name = (TextView) findViewById(R.id.lei_xiangname);        lei_xiangback = (ImageView) findViewById(R.id.lei_xiangback);        //加入购物车的按钮        lei_xiangbutton = (Button) findViewById(R.id.lei_xiangbutton);        Intent intent = getIntent();        pid = intent.getStringExtra("pid");        Log.i("ppp", pid +"");        //实例化p        two = new XPresenter(this);        addPresenter = new AddPresenter(this);        HashMap<String, String> map = new HashMap<>();        map.put("source", "android");        map.put("uid", "1338");        map.put("pid", pid);        Log.i("mmm",map+"");        two.getData(map);        two.attachView(this);        lei_xiangbutton.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View view) {                HashMap<String, String> map = new HashMap<>();                map.put("source", "android");                map.put("uid", "1338");                map.put("pid", pid);                Log.i("mmm",map+"");                addPresenter.getData(map);            }        });        addPresenter.attachView(this);        lei_xiangback.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View view) {                finish();            }        });    }    @Override    public void onDSuccess(Object o) {        XBeans oo=(XBeans)o;        double bargainPrice = oo.getData().getBargainPrice();        String images = oo.getData().getImages();        String title = oo.getData().getTitle();        name.setText(title);        prices.setText("¥:" + bargainPrice + "");        String[] split = images.split("\\|");        Glide.with(this).load(split[0]).into(img);    }    @Override    public void onDFiled(Exception e) {    }    //加入购物车    @Override    public void onASuccess(Object o) {        AddBean oo=(AddBean)o;        String msg = oo.getMsg();        Toast.makeText(XiangQingActivity.this,msg, Toast.LENGTH_SHORT).show();    }    @Override    public void onAFiled(Exception e) {    }}



AddViews接口

public interface AddViews {    void onASuccess(Object o);    void onAFiled(Exception e);}


AddDeleteView类

import android.content.Context;import android.content.res.TypedArray;import android.graphics.Color;import android.util.AttributeSet;import android.view.View;import android.widget.EditText;import android.widget.LinearLayout;import android.widget.TextView;import com.bwei.goshopping.R;/** * Created by HQ on 2017/12/19. */    public class AddDeleteView extends LinearLayout {        private OnAddDelClickListener listener;        private EditText etNumber;        //对外提供一个点击的回调接口        public interface OnAddDelClickListener{            void onAddClick(View v);            void onDelClick(View v);        }        public void setOnAddDelClickListener(OnAddDelClickListener listener){            if(listener!=null){                this.listener=listener;            }        }        public AddDeleteView(Context context) {            this(context,null);        }        public AddDeleteView(Context context, AttributeSet attrs) {            this(context, attrs,0);        }        public AddDeleteView(Context context, AttributeSet attrs, int defStyleAttr) {            super(context, attrs, defStyleAttr);            initView(context, attrs, defStyleAttr);        }        private void initView(Context context, AttributeSet attrs, int defStyleAttr) {            View.inflate(context, R.layout.layout_add_delete,this);            //获取控件            TextView txtDelete=findViewById(R.id.txt_delete);            TextView txtAdd=findViewById(R.id.txt_add);            etNumber = findViewById(R.id.et_number);            TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.AddDeleteViewStyle);            String leftText = typedArray.getString(R.styleable.AddDeleteViewStyle_left_text);            String rightText = typedArray.getString(R.styleable.AddDeleteViewStyle_right_text);            String middleText = typedArray.getString(R.styleable.AddDeleteViewStyle_middle_text);            int color = typedArray.getColor(R.styleable.AddDeleteViewStyle_left_text_color, Color.BLACK);            txtDelete.setText(leftText);            txtAdd.setText(rightText);            etNumber.setText(middleText);            txtDelete.setTextColor(color);            //回收            typedArray.recycle();            txtDelete.setOnClickListener(new OnClickListener() {                @Override                public void onClick(View view) {                    listener.onDelClick(view);                }            });            txtAdd.setOnClickListener(new OnClickListener() {                @Override                public void onClick(View view) {                    listener.onAddClick(view);                }            });        }        //对外提供一个修改数字的方法        public void setNumber(int number){            if(number>0){                etNumber.setText(number+"");            }        }        //对外提供一个获取当前数字的方法        public int getNumber(){            String string = etNumber.getText().toString();            int i = Integer.parseInt(string);            return i;        }    }MainActivity类 
import android.content.DialogInterface;import android.content.Intent;import android.os.Bundle;import android.support.v7.app.AlertDialog;import android.support.v7.app.AppCompatActivity;import android.view.View;import android.widget.Button;import android.widget.CheckBox;import android.widget.ExpandableListView;import android.widget.TextView;import android.widget.Toast;import com.bwei.goshopping.R;import com.bwei.goshopping.adapter.Goods;import com.bwei.goshopping.bean.DeleteBean;import com.bwei.goshopping.bean.GoodsChilde;import com.bwei.goshopping.bean.GoodsGroup;import com.bwei.goshopping.presenter.DeletePresenter;import com.bwei.goshopping.presenter.PresenterTwo;import java.util.ArrayList;import java.util.HashMap;import java.util.List;public class MainActivity extends AppCompatActivity implements GoodsViews, DeleteViews {    private ExpandableListView exListView;    public CheckBox all_checKbox;    private TextView total_price;    private TextView total_number;    private TextView pay;    //新建两个集合    List<GoodsGroup> list = new ArrayList<GoodsGroup>();    List<List<GoodsChilde>> list2 = new ArrayList<List<GoodsChilde>>();    private PresenterTwo two;    private Goods goods;    private TextView edit;    private boolean flagg = true;    public DeletePresenter presenter;    private Button delete_all;    private TextView ok;    private HashMap<String, String> map;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        //获取控件,获取完直接去p层解析数据        exListView = (ExpandableListView) findViewById(R.id.exListView);        all_checKbox = (CheckBox) findViewById(R.id.all_chekbox);        total_price = (TextView) findViewById(R.id.total_price);        total_number = (TextView) findViewById(R.id.total_number);        pay = (TextView) findViewById(R.id.tv_go_to_pay);        edit = (TextView) findViewById(R.id.edit);        ok = (TextView) findViewById(R.id.ok);        delete_all = (Button) findViewById(R.id.delete_all);        exListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {            @Override            public boolean onChildClick(ExpandableListView parent, View v,                                        int groupPosition, int childPosition, long id) {                Intent intent = new Intent(MainActivity.this, XiangQingActivity.class);                int pid = list2.get(groupPosition).get(childPosition).getPid();                intent.putExtra("pid",pid+"");                startActivity(intent);                return true;            }        });        //实例化p        two = new PresenterTwo(this, list, list2);        presenter = new DeletePresenter(this);        map = new HashMap<>();        map.put("source", "android");        map.put("uid", "1284");        two.attachView(this);        //全选按钮的点击事件        all_checKbox.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View view) {                //获取到全选按钮的状态                boolean checked = all_checKbox.isChecked();                for (GoodsGroup i : list) {                    //把状态赋给父级                    i.setCheckbox(checked);                }                //子级的状态                for (List<GoodsChilde> i1 : list2) {                    for (int j = 0; j < i1.size(); j++) {                        i1.get(j).setCheckchild(checked);                    }                }                //刷新适配器                goods.notifyDataSetChanged();                //计算的方法                changesum(list2);            }        });        //删除条目的逻辑        edit.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View view) {                ok.setVisibility(View.VISIBLE);                edit.setVisibility(View.GONE);                delete_all.setVisibility(View.VISIBLE);                pay.setVisibility(View.GONE);                //遍历子级的集合                for (List<GoodsChilde> i1 : list2) {                    for (int i = 0; i < i1.size(); i++) {                        i1.get(i).setBtn(flagg);                    }                }                flagg = !flagg;                goods.notifyDataSetChanged();            }        });        ok.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View view) {                ok.setVisibility(View.GONE);                edit.setVisibility(View.VISIBLE);                delete_all.setVisibility(View.GONE);                pay.setVisibility(View.VISIBLE);                //遍历子级的集合                for (List<GoodsChilde> i1 : list2) {                    for (int i = 0; i < i1.size(); i++) {                        i1.get(i).setBtn(flagg);                    }                }                flagg = !flagg;                goods.notifyDataSetChanged();            }        });        delete_all.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View view) {                AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);                builder.setIcon(R.mipmap.ic_launcher_round);                builder.setTitle("删除操作");                builder.setMessage("确定删除选中商品吗?");                builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {                    private int pid;                    @Override                    public void onClick(DialogInterface dialog, int which) {                        for (int i = 0; i < list.size(); i++) {                            boolean gropuCb = list.get(i).isCheckbox();                            if (gropuCb) {                                list.remove(i);                            }                        }                        for (int t = 0; t < list2.size(); t++) {                            for (int j = 0; j < list2.get(t).size(); j++) {                                pid = list2.get(t).get(j).getPid();                                boolean childCb = list2.get(t).get(j).isCheckchild();                                if (childCb) {                                    HashMap<String, String> map = new HashMap<>();                                    map.put("source", "android");                                    map.put("uid", "1284");                                    map.put("pid", pid + "");                                    presenter.getData(map);                                    list2.get(t).remove(j);                                }                            }                            if (all_checKbox.isChecked()) {                                list.clear();                                list2.clear();                            }                            goods.notifyDataSetChanged();                        }                    }                });                //    设置一个NegativeButton                builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {                    @Override                    public void onClick(DialogInterface dialog, int which) {                        Toast.makeText(MainActivity.this, "您取消了删除" + which, Toast.LENGTH_SHORT).show();                    }                });                //    设置一个NeutralButton                builder.setNeutralButton("忽略", new DialogInterface.OnClickListener() {                    @Override                    public void onClick(DialogInterface dialog, int which) {                        Toast.makeText(MainActivity.this, "您忽略了该操作" + which, Toast.LENGTH_SHORT).show();                    }                });                //    显示出该对话框                builder.show();            }        });    }    @Override    protected void onResume() {        super.onResume();        list.clear();        list2.clear();        two.getData(map);        //创建适配器        goods = new Goods(this, list, list2);        //设置适配器        exListView.setAdapter(goods);        //刷新适配器        goods.notifyDataSetChanged();    }    //计算的逻辑    public void changesum(List<List<GoodsChilde>> childBeen) {        double sum = 0;        int count = 0;        for (List<GoodsChilde> i1 : childBeen) {            for (int r = 0; r < i1.size(); r++) {                boolean childCb1 = i1.get(r).isCheckchild();                if (childCb1) {                    double price = i1.get(r).getPrice();                    int num = i1.get(r).getNum();                    sum += num * price;                    count += num;                }            }        }        total_price.setText("¥:" + sum);        total_number.setText("共计有" + count + "件商品");    }    @Override    public void onSuccess(List<GoodsGroup> lists, List<List<GoodsChilde>> list2s) {        list.addAll(lists);        list2.addAll(list2s);        //二级列表默认展开        for (int i = 0; i < goods.getGroupCount(); i++) {            exListView.expandGroup(i);        }    }    @Override    public void onFiled(Exception e) {    }    //删除    @Override    public void onDSuccess(Object o) {        DeleteBean oo = (DeleteBean) o;        String msg = oo.getMsg();        Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();    }    @Override    public void onDFiled(Exception e) {    }}adapter包
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.EditText;import android.widget.ImageView;import android.widget.TextView;import android.widget.Toast;import com.bumptech.glide.Glide;import com.bwei.goshopping.R;import com.bwei.goshopping.bean.GoodsChilde;import com.bwei.goshopping.bean.GoodsGroup;import com.bwei.goshopping.view.AddDeleteView;import com.bwei.goshopping.view.MainActivity;import java.util.HashMap;import java.util.List;/** * Created by HQ on 2017/11/21. */public class Goods extends BaseExpandableListAdapter {    private Context context;    //传过来两个集合    private List<GoodsGroup> list;    private List<List<GoodsChilde>> list2;    MainActivity con;    //有参构造    public Goods(Context context, List<GoodsGroup> list, List<List<GoodsChilde>> list2) {        this.context = context;        this.list = list;        this.list2 = list2;        con=(MainActivity)context;    }    @Override    public int getGroupCount() {        return list.size();    }    @Override    public int getChildrenCount(int i) {        return list2.get(i).size();    }    @Override    public Object getGroup(int i) {        return list.size();    }    @Override    public Object getChild(int i, int i1) {        return list2.get(i).get(i1).getChildTitle();    }    @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(final int i, boolean b, View view, ViewGroup viewGroup) {        final GroupViewHolder holder;        if(view==null){            holder=new GroupViewHolder();            //绘制父级视图            view=View.inflate(context, R.layout.ex_group_item,null);            holder.cb=(CheckBox)view.findViewById(R.id.group_checkbox);            holder.name=(TextView)view.findViewById(R.id.shop_name);            view.setTag(holder);        }else{            holder=(GroupViewHolder)view.getTag();        }        //设置父级的选中状态        holder.cb.setChecked(list.get(i).isCheckbox());        //得到名字        holder.name.setText(list.get(i).getGrouptitle());        //设置父级选择框的点击事件        holder.cb.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View view) {                //父级当前框的选择状态,默认为未选中                boolean checked = holder.cb.isChecked();                //设置显示                list.get(i).setCheckbox(checked);                MainActivity con=(MainActivity)context;//获取到Main2Activity                //遍历父级的集合                for (GoodsGroup ii:list){                    boolean checkbox = ii.isCheckbox();                    if(!checkbox){//如果父级没有勾选                        con.all_checKbox.setChecked(false);//设置全选按钮也不勾选                        break;                    }else{                        con.all_checKbox.setChecked(true);                    }                }                //勾选执行计算的方法                con.changesum(list2);                notifyDataSetChanged();                //获取到我们子级的集合长度                int size = list2.get(i).size();                //如果我们的父级全部被选中                if(checked){                    //那么你就遍历子级的长度                    for (int j=0;j<size;j++){                        //将我们的子级全部都选中                        list2.get(i).get(j).setCheckchild(true);                    }                }else{                    for (int j=0;j<size;j++){                        list2.get(i).get(j).setCheckchild(false);                    }                }                //刷新我们的适配器                con.changesum(list2);                notifyDataSetChanged();            }        });        return view;    }    //子级的展示    @Override    public View getChildView(final int i, final int i1, boolean b, View view, ViewGroup viewGroup) {        final ChildViewHolder holder;        if(view==null){            holder=new ChildViewHolder();            //绘制子集视图            view=View.inflate(context, R.layout.ex_child_item,null);            holder.ch2=view.findViewById(R.id.child_checkbox);//子级的选择框            holder.title=view.findViewById(R.id.shop_title);//子级的标题            holder.img=view.findViewById(R.id.shop_img);//图片            holder.et_number=view.findViewById(R.id.et_number);//加减中间的数量            holder.price=view.findViewById(R.id.shop_price);//价格            holder.txt_delete=view.findViewById(R.id.txt_delete);//加减器的减            holder.txt_add=view.findViewById(R.id.txt_add);//加减器的加            holder.txt_delete.setText("-");//设置显示减号            holder.txt_add.setText("+");//设置显示加号            holder.jiajia=view.findViewById(R.id.adv);//设置显示加减器            holder.jiajia.setNumber(list2.get(i).get(i1).getNum());//自定义view修改数字的方法            holder.btn=view.findViewById(R.id.shop_delete);//删除的按钮            view.setTag(holder);        }else{            holder=(ChildViewHolder)view.getTag();        }        String shul = list2.get(i).get(i1).getShul();        holder.et_number.setText(shul);        //执行删除的方法        holder.btn.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View view) {                int size = list2.get(i).size();                if(size==1){                    list2.remove(i);                    list.remove(i);                    HashMap<String, String> map = new HashMap<>();                    map.put("uid","1338");                    int pid = list2.get(i).get(i1).getPid();                    map.put("pid",pid+"");                    con.presenter.getData(map);                    notifyDataSetChanged();                }else{                    list2.get(i).remove(i1);                }                //点击删除后隐藏所有删除按钮                for (List<GoodsChilde> i1:list2){                    for(int r=0;r<i1.size();r++) {                        i1.get(r).setBtn(false);                    }                }                notifyDataSetChanged();                con.changesum(list2);            }        });        //必须要设置,不然点击加减会崩,加减的点击事件        holder.jiajia.setOnAddDelClickListener(new AddDeleteView.OnAddDelClickListener() {            @Override            public void onAddClick(View v) {                int number = holder.jiajia.getNumber();                number++;                holder.jiajia.setNumber(number);                list2.get(i).get(i1).setNum(number);                con.changesum(list2);//计算的方法            }            @Override            public void onDelClick(View v) {                int number = holder.jiajia.getNumber();                number--;                if(number==1){                    Toast ts = Toast.makeText(con,"最小数量为1", Toast.LENGTH_LONG);                    ts.show() ;                }                holder.jiajia.setNumber(number);                list2.get(i).get(i1).setNum(number);                con.changesum(list2);            }        });        //子级的选择框        holder.ch2.setChecked(list2.get(i).get(i1).isCheckchild());        holder.title.setText(list2.get(i).get(i1).getChildTitle());        //图片路径拆分        String img = list2.get(i).get(i1).getImg();        String[] split = img.split("\\!");        Glide.with(context).load(split[0]).into(holder.img);        holder.price.setText(list2.get(i).get(i1).getPrice()+"");        //子级的选择框逻辑        holder.ch2.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View view) {                //定义一个flag用于跳出循环                boolean flag=false;                //获取我们子级的选中状态                boolean checked = holder.ch2.isChecked();                //将选中状态返回给我们存放子级的集合中                list2.get(i).get(i1).setCheckchild(checked);                //获取到Activity                MainActivity con=(MainActivity)context;                //循环我们的子级集合                for (List<GoodsChilde> i1:list2){                    //循环第二层的集合                    for (int j=0;j<i1.size();j++){                        //获取到子级条目数的选中状态                        boolean chokx = i1.get(j).isCheckchild();                        //如果我们的子级条目有一条未被选中                        if(!chokx){                            //那么就让我们的全选按钮为未选中                            con.all_checKbox.setChecked(false);                            //同时将父级的按钮也变为未选中                            list.get(i).setCheckbox(false);                            //flagtrue,跳出本层的循环                            flag=true;                            break;                        }else{                            con.all_checKbox.setChecked(true);                            list.get(i).setCheckbox(true);                        }                    }                    if (flag){                        break;                    }                }                con.changesum(list2);                //遍历每一个父级下面的子级集合判断                //获取到子级的集合长度                int size = list2.get(i).size();                //遍历子级集合                for (int e=0;e<size;e++){                    //获取到子级的选中状态                    boolean chokx = list2.get(i).get(e).isCheckchild();                    //如果子级有一条未被选中                    if(!chokx){                        //那么我们的父级按钮就不会被选中                        list.get(i).setCheckbox(false);                        break;                    }else{                        list.get(i).setCheckbox(true);                    }                }                notifyDataSetChanged();                con.changesum(list2);            }        });        //控制删除按钮的显隐        if(list2.get(i).get(i1).isBtn()){            holder.btn.setVisibility(View.VISIBLE);        }else{            holder.btn.setVisibility(View.INVISIBLE);        }        return view;    }    @Override    public boolean isChildSelectable(int i, int i1) {        return true;    }    //两个ViewHolder内部类    class GroupViewHolder{        //控件        CheckBox cb;        TextView name;    }    class ChildViewHolder{        CheckBox ch2;        TextView title;        ImageView img;        TextView price;        TextView txt_delete;        EditText et_number;        TextView txt_add;        AddDeleteView jiajia;        Button btn;    }}
 


原创粉丝点击