仿京东购物车

来源:互联网 发布:算法 中文版 pdf 编辑:程序博客网 时间:2024/05/29 16:52

一.首先是二级列表的适配器

package com.bwie.skn.moni.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.ImageView;import android.widget.TextView;import android.widget.Toast;import com.bumptech.glide.Glide;import com.bwie.skn.moni.R;import com.bwie.skn.moni.bean.Child;import com.bwie.skn.moni.bean.Group;import com.bwie.skn.moni.deleteShopping.DeletePresenter;import com.bwie.skn.moni.deleteShopping.DeleteView;import com.bwie.skn.moni.shoppingCar.ShoppingCartActivity;import java.util.List;/** * author:Created by Conan on 2017/12/16. */public class CarExpandAdapter extends BaseExpandableListAdapter{    private Context context;    private List<Group> groupList;    private List<List<Child>> childList;    private ShoppingCartActivity s;    public static boolean flog;    public CarExpandAdapter(Context context, List<Group> groupList, List<List<Child>> childList,ShoppingCartActivity s) {        this.context = context;        this.groupList = groupList;        this.childList = childList;        this.s = s;    }    @Override    public int getGroupCount() {        return groupList.size();    }    @Override    public int getChildrenCount(int i) {        return childList.get(i).size();    }    @Override    public Object getGroup(int i) {        return groupList.get(i);    }    @Override    public Object getChild(int i, int i1) {        return childList.get(i).get(i1);    }    @Override    public long getGroupId(int i) {        return i;    }    @Override    public long getChildId(int i, int i1) {        return i1;    }    @Override    public boolean hasStableIds() {        return false;    }    //第一级列表viewhodel    class GroupViewHolder{        CheckBox group_box;        TextView group_tv;    }    //第二级列表的viewhodel    class ChildViewHodel{        CheckBox child_box;        ImageView child_iv;        TextView child_tv_name;        TextView child_tv_attr;        TextView child_tv_price;        TextView child_tv_num;        TextView child_tv_minus;        TextView child_tv_show_num;        TextView child_tv_add;        Button delete;    }    @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.group_layout,null);            holder.group_box = view.findViewById(R.id.group_box);            holder.group_tv = view.findViewById(R.id.group_tv);            view.setTag(holder);        }else{            holder = (GroupViewHolder) view.getTag();        }        holder.group_tv.setText(groupList.get(i).getName());        holder.group_box.setChecked(groupList.get(i).isFlag());        holder.group_box.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View view) {                //group布尔值变成选中状态                groupList.get(i).setFlag(holder.group_box.isChecked());                //遍历Group的集合                for (int i=0;i<groupList.size();i++){                    //如果有一个未选中  全选变成FALSE并跳出                    if (!groupList.get(i).isFlag()){                        s.getisAll(false);                        break;                    }else{                        s.getisAll(true);                    }                }                //Child集合布尔值为选中的状态                for (int j=0;j<childList.get(i).size();j++){                    childList.get(i).get(j).setFlag(holder.group_box.isChecked());                }                //刷新适配器                notifyDataSetChanged();                s.js();            }        });        return view;    }    @Override    public View getChildView(final int i, final int i1, boolean b, View view, ViewGroup viewGroup) {        final  ChildViewHodel hodel;        if (view == null){            hodel = new ChildViewHodel();            view = View.inflate(context,R.layout.child_layout,null);            hodel.child_box=view.findViewById(R.id.child_box);            hodel.child_iv = view.findViewById(R.id.child_iv);            hodel.child_tv_name = view.findViewById(R.id.child_tv_name);            hodel.child_tv_attr = view.findViewById(R.id.child_tv_attr);            hodel.child_tv_price = view.findViewById(R.id.child_tv_price);            hodel.child_tv_minus = view.findViewById(R.id.child_tv_minus);            hodel.child_tv_show_num = view.findViewById(R.id.child_tv_show_num);            hodel.child_tv_add = view.findViewById(R.id.child_tv_add);            hodel.child_tv_num = view.findViewById(R.id.child_tv_num);            hodel.delete=view.findViewById(R.id.delete);            view.setTag(hodel);        }else{            hodel = (ChildViewHodel) view.getTag();        }        hodel.child_tv_name.setText(childList.get(i).get(i1).getTitle());        hodel.child_tv_show_num.setText(childList.get(i).get(i1).getNum()+"");        hodel.child_tv_attr.setText(childList.get(i).get(i1).getColor());        hodel.child_tv_price.setText(childList.get(i).get(i1).getPrice()+"");        Glide.with(context).load(childList.get(i).get(i1).getImage().split("\\|")[0]).into(hodel.child_iv);        hodel.child_box.setChecked(childList.get(i).get(i1).isFlag());        hodel.delete.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View view) {                DeletePresenter presenter = new DeletePresenter(new DeleteView() {                    @Override                    public void onDeleteFailure(String error) {                        Toast.makeText(context, error, Toast.LENGTH_SHORT).show();                    }                    @Override                    public void onDeleteSuccesss(String code) {                        Toast.makeText(context, "删除成功", Toast.LENGTH_SHORT).show();                    }                });                int pid = childList.get(i).get(i1).getPid();                presenter.verfiy(3381+"",pid+"");                //从新请求网络                s.setSelectCar();                notifyDataSetChanged();            }        });        hodel.child_box.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View view) {                //Child布尔值变成选中状态                childList.get(i).get(i1).setFlag(hodel.child_box.isChecked());                //遍历Child集合                for (int i=0;i<childList.size();i++){                    for (int j=0;j<childList.get(i).size();j++){                        //如果有一个未选中     全选与商家按钮变成false并跳出                        if(!childList.get(i).get(j).isFlag()){                            groupList.get(i).setFlag(false);                            s.getisAll(false);                            break;                        }else{//全部选中  全选与商家按钮变成true                            groupList.get(i).setFlag(true);                            s.getisAll(false);                        }                    }                }                //二次遍历                for(int i=0;i<groupList.size();i++){                    boolean flag = groupList.get(i).isFlag();                    if(flag){                        s.getisAll(true);                    }else{                        s.getisAll(false);                        break;                    }                }                notifyDataSetChanged();                //计算加减                s.js();            }        });        ////        hodel.child_tv_minus.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View view) {                String num = hodel.child_tv_show_num.getText().toString();                int num1 =  Integer.parseInt(num);                num1--;                childList.get(i).get(i1).setNum(num1);                hodel.child_tv_show_num.setText(childList.get(i).get(i1).getNum()+"");                notifyDataSetChanged();                s.js();            }        });        hodel.child_tv_add.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View view) {                String num = hodel.child_tv_show_num.getText().toString();                int num1 =  Integer.parseInt(num);                num1++;                childList.get(i).get(i1).setNum(num1);                hodel.child_tv_show_num.setText(childList.get(i).get(i1).getNum()+"");                notifyDataSetChanged();                s.js();            }        });        return view;    }    @Override    public boolean isChildSelectable(int i, int i1) {        return false;    }}

二.activity中的代码

package com.bwie.skn.moni.shoppingCar;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.CheckBox;import android.widget.ExpandableListView;import android.widget.TextView;import com.bwie.skn.moni.R;import com.bwie.skn.moni.adapter.CarExpandAdapter;import com.bwie.skn.moni.bean.Child;import com.bwie.skn.moni.bean.Group;import com.bwie.skn.moni.bean.SelectCarBean;import com.bwie.skn.moni.indent.IndentActivity;import java.util.ArrayList;import java.util.List;public class ShoppingCartActivity extends AppCompatActivity implements ISelectCarView,View.OnClickListener{    private boolean isLogin;    private SelectCarPresenter selectCarPresenter;    private ExpandableListView car_elv;    private List<Group> glist = new ArrayList<>();    private List<List<Child>> clist = new ArrayList<>();    private CarExpandAdapter carExpandAdapter;    private TextView edit_tv;    private CheckBox chooseAll;    private TextView totalPrice;    private TextView btnAmount;    private boolean isAll;    private double p;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_shoppingcar);        //初始化数据        init();        chooseAll.setOnClickListener(this);        btnAmount.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View view) {                Intent intent = new Intent(ShoppingCartActivity.this, IndentActivity.class);                intent.putExtra("price",p+"");                startActivity(intent);            }        });    }    /**     * 查询购物车     */    private void selectShoppingCar() {            selectCarPresenter = new SelectCarPresenter(this);            selectCarPresenter.excuteSelectCarData(3381);            carExpandAdapter = new CarExpandAdapter(this,glist,clist,this);            car_elv.setAdapter(carExpandAdapter);    }    /**     * 初始化属性     */    private void init() {        car_elv = (ExpandableListView) findViewById(R.id.car_elv);        edit_tv = (TextView) findViewById(R.id.edit_tv);        chooseAll = (CheckBox) findViewById(R.id.chooseAll);        totalPrice = (TextView) findViewById(R.id.totalPrice);        btnAmount = (TextView) findViewById(R.id.btnAmount);        //登录购物车        selectShoppingCar();    }    @Override    public void onFailed(String msg) {    }    @Override    public void onSuccess(List<SelectCarBean.DataBean> data) {        glist.clear();        clist.clear();        for(int i = 0;i<data.size();i++){            glist.add(new Group(false,data.get(i).getSellerName()));            List<SelectCarBean.DataBean.ListBean> list = data.get(i).getList();            List<Child> cl = new ArrayList<>();            for (int j = 0; j< list.size(); j++){                cl.add(new Child(false, list.get(j).getTitle(),list.get(j).getPrice(), list.get(j).getImages(), list.get(j).getNum(),list.get(j).getSubhead(),list.get(j).getPid()));            }            clist.add(cl);        }        for(int s = 0; s < carExpandAdapter.getGroupCount(); s++){            car_elv.expandGroup(s);        }        carExpandAdapter.notifyDataSetChanged();    }    @Override    public void onResume() {        super.onResume();        init();    }    /**     * 反选     * @param isAll     */    public void getisAll(Boolean isAll) {        chooseAll.setChecked(isAll);    }    /**     * 全选按钮     * @param view     */    @Override    public void onClick(View view) {        isAll = chooseAll.isChecked();        if (!(isAll==true)) {            for (int i = 0; i < glist.size(); i++) {                glist.get(i).setFlag(false);                Log.e("Song","123");            }            for (int i=0 ;i<clist.size();i++){                for (int j=0;j<clist.get(i).size();j++){                    clist.get(i).get(j).setFlag(false);                }            }            if (isAll==true){                isAll=false;            }            js();            carExpandAdapter.notifyDataSetChanged();        } else {            for (int i = 0; i < glist.size(); i++) {                glist.get(i).setFlag(true);            }            for (int i=0 ;i<clist.size();i++){                for (int j=0;j<clist.get(i).size();j++){                    clist.get(i).get(j).setFlag(true);                }            }            if (isAll==false){                isAll=true;            }            js();            carExpandAdapter.notifyDataSetChanged();        }    }    //结算    public void js(){        p = 0;        int s = 0;//选中商品数量        for(int i=0;i<clist.size();i++){            for(int j=0;j<clist.get(i).size();j++){                if(clist.get(i).get(j).isFlag()){                    double price = clist.get(i).get(j).getPrice();                    int num = clist.get(i).get(j).getNum();                    p += price * num;                    s++;                }            }        }        //DecimalFormat df   = new DecimalFormat("######0.00");        totalPrice.setText("总价:"+ p +"¥");        btnAmount.setText("结算:("+s+")");    }    /**     * 请求网络的方法     */    public void setSelectCar(){        selectCarPresenter.excuteSelectCarData(3381);    }}

三.三个布局

1主布局

<?xml version="1.0" encoding="utf-8"?><LinearLayout    xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical" android:layout_width="match_parent"    android:layout_height="match_parent">    <RelativeLayout        android:id="@+id/car_title"        android:layout_width="match_parent"        android:layout_height="0dp"        android:layout_weight="1"        android:background="#fff"        >        <TextView            android:layout_width="match_parent"            android:layout_height="match_parent"            android:gravity="center"            android:text="购物车"            android:textColor="#000"            android:textSize="35dp"            />        <TextView            android:id="@+id/edit_tv"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_weight="1.5"            android:text="编辑"            android:textSize="20dp"            android:layout_marginRight="30dp"            android:layout_centerVertical="true"            android:layout_alignParentRight="true"            android:layout_alignParentEnd="true"            android:layout_marginEnd="30dp" />    </RelativeLayout>    <ExpandableListView        android:id="@+id/car_elv"        android:layout_width="match_parent"        android:layout_height="0dp"        android:layout_weight="9"        android:layout_below="@+id/car_title"></ExpandableListView>    <LinearLayout        android:layout_width="match_parent"        android:layout_height="0dp"        android:layout_weight="1"        android:orientation="horizontal"        android:layout_gravity="bottom"        >        <CheckBox            android:id="@+id/chooseAll"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:textSize="25sp"            android:padding="10dp"            android:text="全选"/>        <TextView            android:id="@+id/totalPrice"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:textSize="25sp"            android:layout_weight="1"            android:padding="10dp"            android:gravity="center"            android:text="合计:0.00 ¥"/>        <TextView            android:id="@+id/btnAmount"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="结算 : (0)"            android:gravity="center"            android:background="@android:color/holo_orange_light"            android:textColor="@android:color/black"            android:textSize="25sp"            android:padding="10dp"/>    </LinearLayout></LinearLayout>

2.一级group的布局


<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="horizontal" android:layout_width="match_parent"    android:layout_height="match_parent">    <CheckBox        android:id="@+id/group_box"        android:layout_width="wrap_content"        android:layout_height="wrap_content" />    <TextView        android:id="@+id/group_tv"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="商家"        /></LinearLayout>

3.二级child的布局


<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="horizontal" android:layout_width="match_parent"    android:layout_height="wrap_content">    <CheckBox        android:id="@+id/child_box"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_centerVertical="true"        android:layout_marginLeft="5dp"        android:scaleX="0.6"        android:scaleY="0.6" />    <ImageView        android:id="@+id/child_iv"        android:layout_width="70dp"        android:layout_height="80dp"        android:layout_centerVertical="true"        android:layout_marginLeft="5dp"        android:background="@mipmap/ic_launcher"        android:layout_toRightOf="@id/child_box" />    <LinearLayout        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_marginLeft="10dp"        android:layout_marginTop="15dp"        android:layout_toRightOf="@id/child_iv"        android:orientation="vertical">        <TextView            android:id="@+id/child_tv_name"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="酒红色纯红色纯羊毛西服套装"            android:textColor="@android:color/black"            android:textSize="12sp"            android:textStyle="bold" />        <LinearLayout            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:orientation="horizontal">            <TextView                android:id="@+id/child_tv_attr"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_marginTop="3dp"                android:text="属性:粉蓝色"                android:textSize="12sp"                android:textColor="@color/colorPrimary" />        </LinearLayout>        <LinearLayout            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_marginTop="4dp"            android:orientation="horizontal">            <TextView                android:id="@+id/child_tv_price"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="¥390"                android:textColor="@android:color/holo_red_dark"                android:textSize="12sp"                android:textStyle="bold" />            <TextView                android:id="@+id/child_tv_num"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_marginLeft="20dp"                android:text="x1"                android:textColor="@android:color/darker_gray" />            <LinearLayout                android:id="@+id/rl_edit"                android:layout_width="120dp"                android:background="@android:color/holo_orange_light"                android:layout_height="30dp"                android:layout_marginLeft="20dp"                >                <TextView                    android:id="@+id/child_tv_minus"                    android:layout_width="0dp"                    android:layout_weight="1"                    android:gravity="center"                    android:textColor="@android:color/black"                    android:background="@android:color/white"                    android:layout_margin="1dp"                    android:layout_height="match_parent"                    android:text=" - " />                <TextView                    android:id="@+id/child_tv_show_num"                    android:layout_width="0dp"                    android:layout_weight="1"                    android:gravity="center"                    android:background="@android:color/white"                    android:layout_margin="1dp"                    android:layout_height="match_parent"                    android:text="1"                    />                <TextView                    android:id="@+id/child_tv_add"                    android:layout_width="0dp"                    android:layout_weight="1"                    android:gravity="center"                    android:layout_margin="1dp"                    android:background="@android:color/white"                    android:layout_height="match_parent"                    android:text=" + " />            </LinearLayout>        </LinearLayout>    </LinearLayout>    <Button   android:id="@+id/delete"    android:layout_width="30dp"    android:layout_height="30dp"    android:layout_alignParentRight="true"    android:layout_centerVertical="true"    android:gravity="center"    android:text="✘"    android:background="@android:color/holo_blue_light"    android:textSize="20sp"    android:textColor="@android:color/holo_green_dark"    android:layout_margin="5dp"    android:visibility="visible" /></RelativeLayout>

四.三个Bean类

1.请求到的bean类


package com.bwie.skn.moni.bean;import java.util.List;/** * author:Created by Conan on 2017/12/16. */public class SelectCarBean {    /**     * msg : 请求成功     * code : 0     * data : [{"list":[{"bargainPrice":399,"createtime":"2017-10-14T21:38:26","detailUrl":"https://item.m.jd.com/product/1439822107.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t5887/201/859509257/69994/6bde9bf6/59224c24Ne854e14c.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5641/233/853609022/57374/5c73d281/59224c24N3324d5f4.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5641/233/853609022/57374/5c73d281/59224c24N3324d5f4.jpg!q70.jpg","num":2,"pid":83,"price":444,"pscid":85,"selected":0,"sellerid":4,"subhead":"满2件,总价打6.50折","title":"Gap男装 休闲舒适简约水洗五袋直筒长裤紧身牛仔裤941825 深灰色 33/32(175/84A)"}],"sellerName":"商家4","sellerid":"4"},{"list":[{"bargainPrice":111.99,"createtime":"2017-10-14T21:39:05","detailUrl":"https://item.m.jd.com/product/4719303.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t9004/210/1160833155/647627/ad6be059/59b4f4e1N9a2b1532.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7504/338/63721388/491286/f5957f53/598e95f1N7f2adb87.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7441/10/64242474/419246/adb30a7d/598e95fbNd989ba0a.jpg!q70.jpg","num":2,"pid":1,"price":118,"pscid":1,"selected":0,"sellerid":17,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellerName":"商家17","sellerid":"17"},{"list":[{"bargainPrice":111.99,"createtime":"2017-10-14T21:48:08","detailUrl":"https://item.m.jd.com/product/4719303.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t9004/210/1160833155/647627/ad6be059/59b4f4e1N9a2b1532.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7504/338/63721388/491286/f5957f53/598e95f1N7f2adb87.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7441/10/64242474/419246/adb30a7d/598e95fbNd989ba0a.jpg!q70.jpg","num":1,"pid":4,"price":999,"pscid":1,"selected":0,"sellerid":20,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellerName":"商家20","sellerid":"20"}]     */    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":399,"createtime":"2017-10-14T21:38:26","detailUrl":"https://item.m.jd.com/product/1439822107.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t5887/201/859509257/69994/6bde9bf6/59224c24Ne854e14c.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5641/233/853609022/57374/5c73d281/59224c24N3324d5f4.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5641/233/853609022/57374/5c73d281/59224c24N3324d5f4.jpg!q70.jpg","num":2,"pid":83,"price":444,"pscid":85,"selected":0,"sellerid":4,"subhead":"满2件,总价打6.50折","title":"Gap男装 休闲舒适简约水洗五袋直筒长裤紧身牛仔裤941825 深灰色 33/32(175/84A)"}]         * sellerName : 商家4         * sellerid : 4         */        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 : 399.0             * createtime : 2017-10-14T21:38:26             * detailUrl : https://item.m.jd.com/product/1439822107.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends             * images : https://m.360buyimg.com/n0/jfs/t5887/201/859509257/69994/6bde9bf6/59224c24Ne854e14c.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5641/233/853609022/57374/5c73d281/59224c24N3324d5f4.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5641/233/853609022/57374/5c73d281/59224c24N3324d5f4.jpg!q70.jpg             * num : 2             * pid : 83             * price : 444.0             * pscid : 85             * selected : 0             * sellerid : 4             * subhead : 满2件,总价打6.50折             * title : Gap男装 休闲舒适简约水洗五袋直筒长裤紧身牛仔裤941825 深灰色 33/32(175/84A)             */            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;            }        }    }}

2.一级group的bean


package com.bwie.skn.moni.bean;/** * author:Created by Conan on 2017/12/16. */public class Group {    private boolean flag;    private String name;    public Group(boolean flag, String name) {        this.flag = flag;        this.name = name;    }    public boolean isFlag() {        return flag;    }    public void setFlag(boolean flag) {        this.flag = flag;    }    public String getName() {        return name;    }    public void setName(String name) {        this.name = name;    }}

3.二级child的布局


package com.bwie.skn.moni.bean;/** * author:Created by Conan on 2017/12/16. */public class Child {    /*    false,    list.get(j).getTitle(),    (float) list.get(j).getPrice(),    list.get(j).getImages(),    list.get(j).getNum()     */    private boolean flag;    private String title;    private double price;    private String image;    private int num;    private String color;    private int pid;    public Child(boolean flag, String title, double price, String image, int num,String color,int pid) {        this.flag = flag;        this.title = title;        this.price = price;        this.image = image;        this.num = num;        this.color = color;        this.pid = pid;    }    public boolean isFlag() {        return flag;    }    public void setFlag(boolean flag) {        this.flag = flag;    }    public String getTitle() {        return title;    }    public void setTitle(String title) {        this.title = title;    }    public double getPrice() {        return price;    }    public void setPrice(double price) {        this.price = price;    }    public String getImage() {        return image;    }    public void setImage(String image) {        this.image = image;    }    public int getNum() {        return num;    }    public void setNum(int num) {        this.num = num;    }    public String getColor() {        return color;    }    public void setColor(String color) {        this.color = color;    }    public int getPid() {        return pid;    }    public void setPid(int pid) {        this.pid = pid;    }}

五.MVP请求的接口

1.view接口


package com.bwie.skn.moni.shoppingCar;import com.bwie.skn.moni.bean.SelectCarBean;import java.util.List;/** * author:Created by Conan on 2017/12/16. */public interface ISelectCarView {    void onFailed(String msg);    void onSuccess(List<SelectCarBean.DataBean> data);}

2.presenter接口


package com.bwie.skn.moni.shoppingCar;import com.bwie.skn.moni.bean.SelectCarBean;import java.util.List;/** * author:Created by Conan on 2017/12/16. */public interface ISelectCarPresenter {    void onFailed(String msg);    void onSuccess(List<SelectCarBean.DataBean> data);}


六.P层


package com.bwie.skn.moni.shoppingCar;import com.bwie.skn.moni.bean.SelectCarBean;import java.util.List;/** * author:Created by Conan on 2017/12/16. */public class SelectCarPresenter implements ISelectCarPresenter{    private ISelectCarView iSelectCarView;    private SelectCarModel selectCarModel;    public SelectCarPresenter (ISelectCarView iSelectCarView){        this.iSelectCarView = iSelectCarView;        selectCarModel = new SelectCarModel();    }    //执行集合信息    public void excuteSelectCarData(int uid){        //传到model        selectCarModel.verifySelectCarInfo(uid,this);    }    @Override    public void onFailed(String msg) {        iSelectCarView.onFailed(msg);    }    @Override    public void onSuccess(List<SelectCarBean.DataBean> data) {        iSelectCarView.onSuccess(data);    }}

七.M层


package com.bwie.skn.moni.shoppingCar;import android.util.Log;import com.bwie.skn.moni.bean.SelectCarBean;import com.bwie.skn.moni.utils.Constant;import com.bwie.skn.moni.utils.GsonUtils;import com.bwie.skn.moni.utils.OKHttpCallBack;import com.bwie.skn.moni.utils.OKHttpUtils;import java.util.HashMap;import java.util.List;import java.util.Map;/** * author:Created by Conan on 2017/12/16. */public class SelectCarModel {    private Map<String,String> map = new HashMap<>();    public void verifySelectCarInfo(int uid, final ISelectCarPresenter iSelectCarPresenter){        Log.e("selectcar",uid+"");        map.put("uid",uid+"");        OKHttpUtils.getInstance().doGet(Constant.SELECTCAR, map, new OKHttpCallBack() {            @Override            public void onFailed(String msg) {                iSelectCarPresenter.onFailed("请求失败");            }            @Override            public void onSuccess(String request) {                SelectCarBean selectCarBean = GsonUtils.getInstance().fromJson(request, SelectCarBean.class);                Log.e("CODEDELETE",selectCarBean.getCode());                String code = selectCarBean.getCode();                if ("0".equals(code)){                    List<SelectCarBean.DataBean> data = selectCarBean.getData();                    iSelectCarPresenter.onSuccess(data);                }else{                    iSelectCarPresenter.onFailed("请求失败");                }            }        });    }}

八.OK请求 在本人的其他博中有,在此不在演示,没有mvp解绑请见谅

此处所用接口也为仿京东接口,请勿使用


原创粉丝点击