购物车

/adapter Myadapter

package ss.com.lbs.gouwuche1.adapter;

import android.content.Context;
import android.net.Uri;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.facebook.drawee.view.SimpleDraweeView;

import java.util.List;

import ss.com.lbs.gouwuche1.R;
import ss.com.lbs.gouwuche1.bean.Gouwuche;
import ss.com.lbs.gouwuche1.view.Iview;

/**
 * author:Created by WangZhiQiang on 2018/4/6.
 */

public class Myadapter  extends BaseExpandableListAdapter {
    private Context context;
    private List<Gouwuche.DataBean> data;
    private Iview iview;

    public Myadapter(Context context, List<Gouwuche.DataBean> data, Iview iview) {
        this.context = context;
        this.data = data;
        this.iview = iview;
    }

    @Override
    public int getGroupCount() {
        return data.size();
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return data.get(groupPosition).getList().size();
    }

    @Override
    public Object getGroup(int groupPosition) {
        return data.get(groupPosition);
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return data.get(groupPosition).getList().get(childPosition);
    }

    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public View getGroupView(final int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        Mypresenthodler mypresenthodler=null;
        if (convertView==null){
            convertView = View.inflate(context, R.layout.gouwuche_prenter, null);
            CheckBox prenter_cb = convertView.findViewById(R.id.prenter_cb);
            TextView prenter_tv = convertView.findViewById(R.id.prenter_tv);
            mypresenthodler=new Mypresenthodler(prenter_cb,prenter_tv);
            convertView.setTag(mypresenthodler);
        }else {
            mypresenthodler = (Mypresenthodler) convertView.getTag();
        }
        mypresenthodler.prenter_tv.setText(data.get(groupPosition).getSellerName());
        mypresenthodler.prenter_cb.setChecked(data.get(groupPosition).isPresenterck());

        //父类的点击事件
        mypresenthodler.prenter_cb.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Gouwuche.DataBean dataBean = data.get(groupPosition);
                boolean isCheked  = dataBean.isPresenterck();
                isCheked=!isCheked;
                dataBean.setPresenterck(isCheked);
                List<Gouwuche.Mybean> list = Myadapter.this.data.get(groupPosition).getList();
                for (int i = 0; i <list.size() ; i++) {
                    list.get(i).setChildck(isCheked);
                }
                iview.heji();
                notifyDataSetChanged();
            }
        });
        return convertView;
    }

    @Override
    public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
        Mychildhodler mychildhodler=null;
        if (convertView==null){
            convertView = View.inflate(context, R.layout.gouwuche_chiled, null);
            CheckBox child_ck = convertView.findViewById(R.id.child_ck);
            SimpleDraweeView child_sd = convertView.findViewById(R.id.child_sd);
            TextView cjild_name = convertView.findViewById(R.id.cjild_name);
            TextView cjild_price = convertView.findViewById(R.id.cjild_price);
            ImageView jian = convertView.findViewById(R.id.jian);
            EditText ed = convertView.findViewById(R.id.ed);
            ImageView jia = convertView.findViewById(R.id.jia);
            mychildhodler=new Mychildhodler(child_ck,child_sd,cjild_name,cjild_price,jian,ed,jia);
            convertView.setTag(mychildhodler);
        }else {
            mychildhodler= (Mychildhodler) convertView.getTag();
        }
        final Gouwuche.Mybean mybean = data.get(groupPosition).getList().get(childPosition);
        mychildhodler.child_ck.setChecked(mybean.isChildck());
        String images = mybean.getImages();
        String[] split = images.split(".jpg");
        mychildhodler.child_sd.setImageURI(Uri.parse(split[0]+".jpg"));
        mychildhodler.cjild_name.setText(mybean.getTitle());
        mychildhodler.cjild_price.setText(mybean.getPrice()+"");
        mychildhodler.ed.setText(mybean.getCount()+1+"");

        mychildhodler.child_ck.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                boolean isCheked  = mybean.isChildck();
                isCheked=!isCheked;
                mybean.setChildck(isCheked);
                boolean flag = true;
                List<Gouwuche.Mybean> list = Myadapter.this.data.get(groupPosition).getList();
                for (int i = 0; i <list.size() ; i++) {
                    if (!list.get(i).isChildck()){
                        flag=false;
                    }

                }
                Myadapter.this.data.get(groupPosition).setPresenterck(flag);
                iview.heji();
                notifyDataSetChanged();
            }
        });

        mychildhodler.jia.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int count = mybean.getCount();
                mybean.setCount(++count);
                iview.heji();
                notifyDataSetChanged();
            }
        });

        mychildhodler.jian.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int count = mybean.getCount();
                if (count>0){
                    count--;
                    mybean.setCount(count);
                }else {
                    Toast.makeText(context,"不能再减了",Toast.LENGTH_SHORT).show();
                }
                iview.heji();
                notifyDataSetChanged();
            }

        });
        return convertView;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }
    class Mychildhodler{
        public CheckBox child_ck;
        public SimpleDraweeView child_sd;
        public TextView cjild_name;
        public TextView cjild_price;
        public ImageView jian;
        public EditText ed;
        public ImageView jia;

        public Mychildhodler(CheckBox child_ck, SimpleDraweeView child_sd, TextView cjild_name, TextView cjild_price, ImageView jian, EditText ed, ImageView jia) {
            this.child_ck = child_ck;
            this.child_sd = child_sd;
            this.cjild_name = cjild_name;
            this.cjild_price = cjild_price;
            this.jian = jian;
            this.ed = ed;
            this.jia = jia;
        }
    }

    class Mypresenthodler{
        public CheckBox prenter_cb;
        public TextView prenter_tv;

        public Mypresenthodler(CheckBox prenter_cb, TextView prenter_tv) {
            this.prenter_cb = prenter_cb;
            this.prenter_tv = prenter_tv;
        }
    }
}





bean    Gouwuche

package ss.com.lbs.gouwuche1.bean;

import java.util.List;

/**
 * author:Created by WangZhiQiang on 2018/4/6.
 */

public class Gouwuche {

    /**
     * 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":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手机"}],"sellerName":"商家2","sellerid":"2"},{"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":1,"pid":61,"price":14999,"pscid":40,"selected":0,"sellerid":5,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"}],"sellerName":"商家5","sellerid":"5"},{"list":[{"bargainPrice":3455,"createtime":"2017-10-14T21:48:08","detailUrl":"https://item.m.jd.com/product/12224420750.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t9106/106/1785172479/537280/253bc0ab/59bf78a7N057e5ff7.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t9106/106/1785172479/537280/253bc0ab/59bf78a7N057e5ff7.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8461/5/1492479653/68388/7255e013/59ba5e84N91091843.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8461/5/1492479653/68388/7255e013/59ba5e84N91091843.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8803/356/1478945529/489755/2a163ace/59ba5e84N7bb9a666.jpg!q70.jpg","num":1,"pid":50,"price":444,"pscid":39,"selected":0,"sellerid":6,"subhead":"【现货新品抢购】全面屏2.0震撼来袭,骁龙835处理器,四曲面陶瓷机","title":"小米(MI) 小米MIX2 手机 黑色 全网通 (6GB+64GB)【标配版】"}],"sellerName":"商家6","sellerid":"6"},{"list":[{"bargainPrice":3455,"createtime":"2017-10-14T21:38:26","detailUrl":"https://item.m.jd.com/product/12224420750.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t9106/106/1785172479/537280/253bc0ab/59bf78a7N057e5ff7.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t9106/106/1785172479/537280/253bc0ab/59bf78a7N057e5ff7.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8461/5/1492479653/68388/7255e013/59ba5e84N91091843.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8461/5/1492479653/68388/7255e013/59ba5e84N91091843.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8803/356/1478945529/489755/2a163ace/59ba5e84N7bb9a666.jpg!q70.jpg","num":4,"pid":56,"price":99,"pscid":39,"selected":1,"sellerid":12,"subhead":"【现货新品抢购】全面屏2.0震撼来袭,骁龙835处理器,四曲面陶瓷机","title":"小米(MI) 小米MIX2 手机 黑色 全网通 (6GB+64GB)【标配版】"}],"sellerName":"商家12","sellerid":"12"},{"list":[{"bargainPrice":22.9,"createtime":"2017-10-03T23:53:28","detailUrl":"https://item.m.jd.com/product/2542855.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t1930/284/2865629620/390243/e3ade9c4/56f0a08fNbd3a1235.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t2137/336/2802996626/155915/e5e90d7a/56f0a09cN33e01bd0.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t1882/31/2772215910/389956/c8dbf370/56f0a0a2Na0c86ea6.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t2620/166/2703833710/312660/531aa913/57709035N33857877.jpg!q70.jpg","num":1,"pid":40,"price":345,"pscid":2,"selected":1,"sellerid":17,"subhead":"三只松鼠零食特惠,专区满99减50,满199减100,火速抢购》","title":"三只松鼠 坚果炒货 零食奶油味 碧根果225g/袋"}],"sellerName":"商家17","sellerid":"17"}]
     */

    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 boolean presenterck;

        public boolean isPresenterck() {
            return presenterck;
        }

        public void setPresenterck(boolean presenterck) {
            this.presenterck = presenterck;
        }

        private List<Mybean> 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<Mybean> getList() {
            return list;
        }

        public void setList(List<Mybean> list) {
            this.list = list;
        }
    }
    public class Mybean{

        /**
         * 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手机
         */
        private int count;
        private boolean childck;
        private double bargainPrice;
        private String createtime;
        private String detailUrl;
        private String images;
        private double num;
        private double pid;
        private double price;
        private double pscid;
        private double selected;
        private double sellerid;
        private String subhead;
        private String title;

        public int getCount() {
            return count;
        }

        public void setCount(int count) {
            this.count = count;
        }

        public boolean isChildck() {
            return childck;
        }

        public void setChildck(boolean childck) {
            this.childck = childck;
        }

        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 double getNum() {
            return num;
        }

        public void setNum(double num) {
            this.num = num;
        }

        public double getPid() {
            return pid;
        }

        public void setPid(double pid) {
            this.pid = pid;
        }

        public double getPrice() {
            return price;
        }

        public void setPrice(double price) {
            this.price = price;
        }

        public double getPscid() {
            return pscid;
        }

        public void setPscid(double pscid) {
            this.pscid = pscid;
        }

        public double getSelected() {
            return selected;
        }

        public void setSelected(double selected) {
            this.selected = selected;
        }

        public double getSellerid() {
            return sellerid;
        }

        public void setSellerid(double 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;
        }
    }
}





// mode  Mymode

package ss.com.lbs.gouwuche1.mode;

import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;
import ss.com.lbs.gouwuche1.bean.Gouwuche;
import ss.com.lbs.gouwuche1.utils.Api;
import ss.com.lbs.gouwuche1.utils.Util;

/**
 * author:Created by WangZhiQiang on 2018/4/6.
 */

public class Mymode {

    public void getgouwuche(final Getgouwuchebean getgouwuchebean){
        Observable<Gouwuche> user = Util.getmInstance().getnetjson(Api.net).getUser();
        user.subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<Gouwuche>() {
                    @Override
                    public void accept(Gouwuche gouwuche) throws Exception {
                        getgouwuchebean.getgouwuchejson(gouwuche);
                    }
                });
    }
    public interface Getgouwuchebean{
        void getgouwuchejson(Gouwuche gouwuche);
    }
}




presenters   Mypresenter

package ss.com.lbs.gouwuche1.presenters;

import android.content.Context;

import java.util.List;

import ss.com.lbs.gouwuche1.bean.Gouwuche;
import ss.com.lbs.gouwuche1.mode.Mymode;
import ss.com.lbs.gouwuche1.view.Iview;

/**
 * author:Created by WangZhiQiang on 2018/4/6.
 */

public class Mypresenter {
    private Context context;
    private Iview iview;
    private Mymode mymode;

    public Mypresenter(Context context, Iview iview) {
        this.context = context;
        this.iview = iview;
        mymode=new Mymode();
    }

    public void getmv(){

        mymode.getgouwuche(new Mymode.Getgouwuchebean() {
            @Override
            public void getgouwuchejson(Gouwuche gouwuche) {
                List<Gouwuche.DataBean> data = gouwuche.getData();
                iview.setadapter(context,data);
            }
        });
    }
}




// utils  Mapp


package ss.com.lbs.gouwuche1.utils;

import android.app.Application;

import com.facebook.drawee.backends.pipeline.Fresco;

/**
 * author:Created by WangZhiQiang on 2018/4/6.
 */

public class Myapp extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        Fresco.initialize(this);
    }
}

/util


package ss.com.lbs.gouwuche1.utils;

import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * author:Created by WangZhiQiang on 2018/4/6.
 */

public class Util {
    private volatile static Util util=null;
    private Util(){

    }
    public static Util getmInstance(){
        if (util==null){
            synchronized (Util.class){
                if (util==null){
                    util=new Util();
                }
            }
        }
        return util;
    }
    public Apiservire getnetjson(String uri) {
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build();

        Apiservire testservive = retrofit.create(Apiservire.class);
        return testservive;

    }
}


/Apiservire

package ss.com.lbs.gouwuche1.utils;

import io.reactivex.Observable;
import retrofit2.http.GET;
import ss.com.lbs.gouwuche1.bean.Gouwuche;

/**
 * author:Created by WangZhiQiang on 2018/4/6.
 */

public interface Apiservire {
    @GET("product/getCarts?source=android&uid=72")
    Observable<Gouwuche> getUser();
}


package ss.com.lbs.gouwuche1.utils;

/**
 * author:Created by WangZhiQiang on 2018/4/6.
 */

public class Api {
    public static String net="http://120.27.23.105/";
}


/// view   Iview


package ss.com.lbs.gouwuche1.view;

import android.content.Context;

import java.util.List;

import ss.com.lbs.gouwuche1.bean.Gouwuche;

/**
 * author:Created by WangZhiQiang on 2018/4/6.
 */

public interface Iview {
    void setadapter(Context context, List<Gouwuche.DataBean> data);
    void heji();
}




/    MainActivity



package ss.com.lbs.gouwuche1;

import android.content.Context;
import android.os.Bundle;
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.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import java.math.BigDecimal;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import ss.com.lbs.gouwuche1.adapter.Myadapter;
import ss.com.lbs.gouwuche1.bean.Gouwuche;
import ss.com.lbs.gouwuche1.presenters.Mypresenter;
import ss.com.lbs.gouwuche1.view.Iview;

public class MainActivity extends AppCompatActivity implements Iview {
    @BindView(R.id.edlist)
    ExpandableListView edlist;
    @BindView(R.id.hj)
    TextView hj;
    @BindView(R.id.jiesuan)
    Button jiesuan;
    @BindView(R.id.cb)
    CheckBox cb;
    @BindView(R.id.tv)
    TextView tv;
    @BindView(R.id.wancheng)
    LinearLayout wancheng;
    @BindView(R.id.bianji)
    LinearLayout bianji;
    @BindView(R.id.shanchu)
    Button shanchu;
    private List<Gouwuche.DataBean> data;
    private Myadapter myadapter;
    boolean flog = true;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        Mypresenter mypresenter=new Mypresenter(this,this);
        mypresenter.getmv();
        wancheng.setVisibility(View.GONE);
        //全选的点击事件
        quanxuan(cb);
        //编辑的点击事件
        tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (flog){
                    tv.setText("完成");
                    flog=false;
                    wancheng.setVisibility(View.VISIBLE);
                    bianji.setVisibility(View.GONE);

                }else {
                    tv.setText("编辑");
                    flog=true;
                    bianji.setVisibility(View.VISIBLE);
                    wancheng.setVisibility(View.GONE);

                }

            }
        });

        //删除的事件
        shanchu();

        edlist.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
            @Override
            public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
                Toast.makeText(MainActivity.this,data.get(groupPosition).getList().get(childPosition).getTitle(),Toast.LENGTH_SHORT).show();
                return true;
            }
        });
    }
    private void shanchu() {
        shanchu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                for (int i = 0; i < data.size(); i++) {
                    List<Gouwuche.Mybean> list = data.get(i).getList();
                    boolean presenterck = data.get(i).isPresenterck();
                    if (presenterck){
                        data.remove(i);
                        heji();
                        myadapter.notifyDataSetChanged();
                    }
                    for (int j = 0; j < list.size(); j++) {
                        boolean childck = list.get(j).isChildck();
                        if (childck) {
                            list.remove(j);
                            heji();
                            myadapter.notifyDataSetChanged();
                        }
                    }
                }
            }
        });
    }

    private void quanxuan(CheckBox cb) {
        cb.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                for (int i = 0; i <data.size() ; i++) {
                    boolean presenterck = data.get(i).isPresenterck();
                    data.get(i).setPresenterck(!presenterck);
                    List<Gouwuche.Mybean> list = data.get(i).getList();
                    for (int j = 0; j <list.size() ; j++) {
                        boolean  childck = list.get(j).isChildck();
                        list.get(j).setChildck(!childck);
                    }
                }
                heji();
                myadapter.notifyDataSetChanged();
            }
        });
    }

    @Override
    public void setadapter(Context context, final List<Gouwuche.DataBean> data) {
        this.data=data;
        myadapter = new Myadapter(context,data,this);
        edlist.setAdapter(myadapter);

    }


    //合计的代码
    @Override
    public void heji() {
        double add=0;
        int count=0;
        for (int i = 0; i <data.size() ; i++) {
            List<Gouwuche.Mybean> list = data.get(i).getList();
            for (int j = 0; j < list.size(); j++) {
                boolean childck = list.get(j).isChildck();
                if (childck){
                    count++;
                    int mycount = list.get(j).getCount() + 1;
                    double mul = mul(list.get(j).getPrice(), mycount);
                    add = add(add, mul);

                }
            }
        }
        hj.setText(add+"");
        jiesuan.setText("去结算"+"("+count+")");

    }

    //乘法
    public static double mul(double v1, double v2) {
        BigDecimal b1 = new BigDecimal(Double.toString(v1));
        BigDecimal b2 = new BigDecimal(Double.toString(v2));
        return b1.multiply(b2).doubleValue();
    }

    //加法
    public static double add(double v1, double v2) {
        BigDecimal b1 = new BigDecimal(Double.toString(v1));
        BigDecimal b2 = new BigDecimal(Double.toString(v2));
        return b1.add(b2).doubleValue();
    }
}




/   activity_main

<?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="ss.com.lbs.gouwuche1.MainActivity">
    <LinearLayout
        android:layout_gravity="center_horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView
            android:textSize="40px"
            android:layout_width="0px"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:text="购物车"
            android:gravity="center_horizontal" />

        <TextView
            android:textSize="40px"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/tv"
            android:text="编辑"/>


    </LinearLayout>

    <ExpandableListView
        android:groupIndicator="@null"
        android:layout_width="match_parent"
        android:layout_height="0px"
        android:layout_weight="1"
        android:id="@+id/edlist"></ExpandableListView>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <CheckBox
            android:textSize="30px"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/cb"
            android:text="全选/反选"/>
        <LinearLayout
            android:id="@+id/bianji"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <TextView
                android:textSize="30px"
                android:layout_marginLeft="30px"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="合计:"/>

            <TextView
                android:textSize="30px"
                android:layout_marginLeft="30px"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/hj"
                android:text="0"/>

            <Button
                android:textSize="30px"
                android:layout_marginLeft="50px"
                android:background="#ff0000"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/jiesuan"
                android:text="去结算"/>
        </LinearLayout>


        <LinearLayout
            android:id="@+id/wancheng"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <Button
                android:layout_marginLeft="150px"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="删除"
                android:textSize="30px"
                android:id="@+id/shanchu"/>


        </LinearLayout>



    </LinearLayout>

</LinearLayout>




  gouwuche_chiled


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:orientation="vertical"
    android:descendantFocusability="blocksDescendants"
    xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
    android:layout_height="match_parent">
     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:orientation="horizontal">
         <CheckBox
             android:focusable="false"
             android:layout_gravity="center_vertical"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:id="@+id/child_ck"/>
          <com.facebook.drawee.view.SimpleDraweeView
              android:layout_marginLeft="50px"
              android:layout_width="200px"
              android:layout_height="200px"
              android:id="@+id/child_sd"/>
         <LinearLayout
             android:layout_marginLeft="20px"
             android:layout_gravity="center_vertical"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:orientation="vertical">
             <TextView
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:id="@+id/cjild_name"
                 android:text="你好啊我来拉别跑啊"/>
             <TextView
                 android:layout_marginTop="60px"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:id="@+id/cjild_price"
                 android:text="你好啊我来拉别跑啊"/>


         </LinearLayout>

         <LinearLayout
             android:layout_marginLeft="-150dp"
             android:layout_marginTop="180px"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:orientation="horizontal">

             <ImageView
                 android:focusable="false"
                 android:id="@+id/jian"
                 android:layout_width="40px"
                 android:layout_height="40px"
                 android:src="@drawable/shopcart_minus_grey"/>
             <EditText
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:id="@+id/ed"
                 android:background="@drawable/shopcart_add_btn"
                 android:paddingBottom="2dp"
                 android:paddingLeft="20dp"
                 android:paddingRight="20dp"
                 android:paddingTop="2dp"
                 />
             <ImageView
                 android:focusable="false"
                 android:id="@+id/jia"
                 android:layout_width="40px"
                 android:layout_height="40px"
                 android:src="@drawable/shopcart_add_red"/>
         </LinearLayout>
     </LinearLayout>

</LinearLayout>



///  gouwuche_prenter



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
   <CheckBox
       android:focusable="false"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:id="@+id/prenter_cb"/>

    <TextView
        android:layout_marginLeft="20px"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/prenter_tv"/>
    </LinearLayout>
</LinearLayout>


///依赖

//butterknife
//    compile 'com.jakewharton:butterknife-compiler:8.0.1'
//    compile 'com.jakewharton:butterknife:8.0.1'
//Dao
    compile 'com.jakewharton:butterknife:8.4.0'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
    compile 'io.reactivex.rxjava2:rxjava:2.0.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'com.facebook.fresco:fresco:0.14.1'



<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="ss.com.lbs.gouwuche1">
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <!--读取网络状态的权限-->
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <application
        android:name=".utils.Myapp"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>







  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值