购物车列表及确认订单页面 - 相关代码(三)

前言

购物车系列文章:
购物车列表及确认订单页面 - 技术分析(一)
购物车列表及确认订单页面 - 相关代码(二)
购物车列表及确认订单页面 - 相关代码(三)
购物车列表及确认订单页面 - 部分知识点思路解析(四)

3>:用Gson解析之后的 ShopCartListBean
public class ShopCartListBean implements Serializable{
    /**
     * msg : 查看成功
     * code : 0
     * data : [{"merchantCode":"3","isLatest":0,"isDeleted":0,"isEnabled":0,"businessName":"北京测试1","id":22,"userId":32,"productList":[{"cartSum":1,"couponOriginalCost":"50","couponName":"哇哇哇哇哇","addTime":1536633418000,"productImg":"5131.png,5132.png,5133.png","currentPrice":"3880","title":"海志Q1复古圆键帽有线键盘无线静音巧克力办公家用笔记本USB接口"},{"cartSum":1,"couponOriginalCost":"200","couponName":"小小苏","addTime":1536633440000,"productImg":"6111.png,6112.png,6113.png","currentPrice":"6900","title":"灭蚊灯家用室内插电式一扫光驱蚊器防蚊灭蚊神器婴儿捕蚊子全自动"},{"cartSum":1,"addTime":1536633428000,"productImg":"5161.png,5162.png,5163.png","currentPrice":"23800","title":"得力9939碎纸机办公迷你家用颗粒电动小型大功率纸张文件粉碎机"},{"cartSum":1,"addTime":1536633434000,"productImg":"6121.png,6122.png,6123.png","currentPrice":"8900","title":"德国灭蚊灯室内一扫光插电式驱蚊器防蚊神器无辐射静音婴儿全自动"}]},{"merchantCode":"4","isLatest":0,"isDeleted":0,"isEnabled":0,"businessName":"北京测试2","id":23,"userId":32,"productList":[{"cartSum":1,"addTime":1536633423000,"productImg":"5141.png,5142.png,5143.png","currentPrice":"3980","title":"HP/惠普S1000无线鼠标静音无声男女生电脑办公笔记本台式无限游戏"}]},{"merchantCode":"5","isLatest":0,"isDeleted":0,"isEnabled":0,"businessName":"北京测试3","id":24,"userId":32,"productList":[{"cartSum":1,"couponOriginalCost":"100","couponName":"嘤嘤嘤","addTime":1536633514000,"productImg":"5151.png,5152.png,5153.png","currentPrice":"79900","title":"康亿B类点钞机新版人民币验钞机银行专用小型便携式办公家用商用"}]}]
     * totalCount : 3
     */

    private String msg;
    private String code;
//    private int totalCount;
    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 int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }*/

    public List<DataBean> getData() {
        return data;
    }

    public void setData(List<DataBean> data) {
        this.data = data;
    }

    public static class DataBean {
        /**
         * merchantCode : 3
         * isLatest : 0
         * isDeleted : 0
         * isEnabled : 0
         * businessName : 北京测试1
         * id : 22
         * userId : 32
         * productList : [{"cartSum":1,"couponOriginalCost":"50","couponName":"哇哇哇哇哇","addTime":1536633418000,"productImg":"5131.png,5132.png,5133.png","currentPrice":"3880","title":"海志Q1复古圆键帽有线键盘无线静音巧克力办公家用笔记本USB接口"},{"cartSum":1,"couponOriginalCost":"200","couponName":"小小苏","addTime":1536633440000,"productImg":"6111.png,6112.png,6113.png","currentPrice":"6900","title":"灭蚊灯家用室内插电式一扫光驱蚊器防蚊灭蚊神器婴儿捕蚊子全自动"},{"cartSum":1,"addTime":1536633428000,"productImg":"5161.png,5162.png,5163.png","currentPrice":"23800","title":"得力9939碎纸机办公迷你家用颗粒电动小型大功率纸张文件粉碎机"},{"cartSum":1,"addTime":1536633434000,"productImg":"6121.png,6122.png,6123.png","currentPrice":"8900","title":"德国灭蚊灯室内一扫光插电式驱蚊器防蚊神器无辐射静音婴儿全自动"}]
         */

        private String merchantCode;
        private int isLatest;
        private int isDeleted;
        private int isEnabled;
        private String businessName;
        private int id;
        private int userId;
        private List<ProductListBean> productList;

        public String getMerchantCode() {
            return merchantCode;
        }

        public void setMerchantCode(String merchantCode) {
            this.merchantCode = merchantCode;
        }

        public int getIsLatest() {
            return isLatest;
        }

        public void setIsLatest(int isLatest) {
            this.isLatest = isLatest;
        }

        public int getIsDeleted() {
            return isDeleted;
        }

        public void setIsDeleted(int isDeleted) {
            this.isDeleted = isDeleted;
        }

        public int getIsEnabled() {
            return isEnabled;
        }

        public void setIsEnabled(int isEnabled) {
            this.isEnabled = isEnabled;
        }

        public String getBusinessName() {
            return businessName;
        }

        public void setBusinessName(String businessName) {
            this.businessName = businessName;
        }

        public int getId() {
            return id;
        }

        public void setId(int id) {
            this.id = id;
        }

        public int getUserId() {
            return userId;
        }

        public void setUserId(int userId) {
            this.userId = userId;
        }

        public List<ProductListBean> getProductList() {
            return productList;
        }

        public void setProductList(List<ProductListBean> productList) {
            this.productList = productList;
        }

        public static class ProductListBean {
            /**
             * cartSum : 1
             * couponOriginalCost : 50
             * couponName : 哇哇哇哇哇
             * addTime : 1536633418000
             * productImg : 5131.png,5132.png,5133.png
             * currentPrice : 3880
             * title : 海志Q1复古圆键帽有线键盘无线静音巧克力办公家用笔记本USB接口
             */

            private int cartSum;
            private String couponOriginalCost;
            private String couponName;
            private long addTime;
            private String productImg;
            private String currentPrice;
            private String title;

            public int getMerchantId() {
                return merchantId;
            }

            public void setMerchantId(int merchantId) {
                this.merchantId = merchantId;
            }

            private int merchantId ;

            public int getCartSum() {
                return cartSum;
            }

            public void setCartSum(int cartSum) {
                this.cartSum = cartSum;
            }

            public String getCouponOriginalCost() {
                return couponOriginalCost;
            }

            public void setCouponOriginalCost(String couponOriginalCost) {
                this.couponOriginalCost = couponOriginalCost;
            }

            public String getCouponName() {
                return couponName;
            }

            public void setCouponName(String couponName) {
                this.couponName = couponName;
            }

            public long getAddTime() {
                return addTime;
            }

            public void setAddTime(long addTime) {
                this.addTime = addTime;
            }

            public String getProductImg() {
                return productImg;
            }

            public void setProductImg(String productImg) {
                this.productImg = productImg;
            }

            public String getCurrentPrice() {
                return currentPrice;
            }

            public void setCurrentPrice(String currentPrice) {
                this.currentPrice = currentPrice;
            }

            public String getTitle() {
                return title;
            }

            public void setTitle(String title) {
                this.title = title;
            }
        }
    }
}
4>:组装数据的MiddleBean
public class MiddleBean implements Serializable{
    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;
    }

    private List<StoreInfo> data ;

    public List<StoreInfo> getData() {
        return data;
    }

    public void setData(List<StoreInfo> data) {
        this.data = data;
    }

    // 店鋪
    public static class StoreInfo implements Serializable{

        // 商家id
        private String id;
        private String name;
        private boolean isChoosed;
        private boolean isEditor; //自己对该组的编辑状态
        private boolean ActionBarEditor;// 全局对该组的编辑状态
        private List<GoodsInfo> goodses ;

        // 商家编码
        private String merchantCode;

        public StoreInfo(){

        }
        public StoreInfo(String id, String merchantCode,String name) {
            this.id = id;
            this.merchantCode = merchantCode ;
            this.name = name;
        }



        public String getMerchantCode() {
            return merchantCode;
        }

        public void setMerchantCode(String merchantCode) {
            this.merchantCode = merchantCode;
        }

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public boolean isChoosed() {
            return isChoosed;
        }

        public void setChoosed(boolean choosed) {
            isChoosed = choosed;
        }

        public boolean isEditor() {
            return isEditor;
        }

        public void setEditor(boolean editor) {
            isEditor = editor;
        }

        public boolean isActionBarEditor() {
            return ActionBarEditor;
        }

        public void setActionBarEditor(boolean actionBarEditor) {
            ActionBarEditor = actionBarEditor;
        }

        public List<GoodsInfo> getGoodses() {
            return goodses;
        }

        public void setGoodses(List<GoodsInfo> goodses) {
            this.goodses = goodses;
        }


        // 商品
        public static class GoodsInfo implements Serializable{

        // 店铺id
        private String stroeId ;

            public String getStroeId() {
                return stroeId;
            }

            public void setStroeId(String stroeId) {
                this.stroeId = stroeId;
            }

            // 商品id
        private String id;
        private String name;
        private boolean isChoosed;
        private String imageUrl;
        private String desc;
        private double price;
        private double prime_price;
        private int postion;
        private int count;
        private String color;
        private String size;
        private int goodsImg;

            private StoreInfo storeInfo ;

            public StoreInfo getStoreInfo() {
                return storeInfo;
            }

            public void setStoreInfo(StoreInfo storeInfo) {
                this.storeInfo = storeInfo;
            }

            public GoodsInfo(){

            }
        public GoodsInfo( String stroeId , String id, String name, String desc,double price, double prime_price,
                         String color, String size, int goodsImg,int count) {
            this.stroeId = stroeId ;
            this.id = id;
            this.name = name;
            this.desc = desc;
            this.price = price;
            this.prime_price = prime_price;
            this.color = color;
            this.size = size;
            this.goodsImg = goodsImg;
            this.count = count;
        }

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public boolean isChoosed() {
            return isChoosed;
        }

        public void setChoosed(boolean choosed) {
            isChoosed = choosed;
        }

        public String getImageUrl() {
            return imageUrl;
        }

        public void setImageUrl(String imageUrl) {
            this.imageUrl = imageUrl;
        }

        public String getDesc() {
            return desc;
        }

        public void setDesc(String desc) {
            this.desc = desc;
        }

        public double getPrice() {
            return price;
        }

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

        public double getPrime_price() {
            return prime_price;
        }

        public void setPrime_price(double prime_price) {
            this.prime_price = prime_price;
        }

        public int getPostion() {
            return postion;
        }

        public void setPostion(int postion) {
            this.postion = postion;
        }

        public int getCount() {
            return count;
        }

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

        public String getColor() {
            return color;
        }

        public void setColor(String color) {
            this.color = color;
        }

        public String getSize() {
            return size;
        }

        public void setSize(String size) {
            this.size = size;
        }

        public int getGoodsImg() {
            return goodsImg;
        }

        public void setGoodsImg(int goodsImg) {
            this.goodsImg = goodsImg;
        }
    }

    }
}
5>:确认订单页面:GoPayCartActivity:
public class GoPayCartActivity extends AppCompatActivity {

    private ListView listView;
    private RelativeLayout layout_title_left;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_go_pay_cart);

        initView() ;
    }

    private void initView() {
        layout_title_left = (RelativeLayout) findViewById(R.id.layout_title_left);


        // 传递过来选中的商品和店铺的集合数据
        List<MiddleBean.StoreInfo> listConfirm = (List<MiddleBean.StoreInfo>) getIntent().getSerializableExtra("listConfirm");
        listView = (ListView) findViewById(R.id.listView);
        ParentShopCartAdapter shopCartAdapter= new ParentShopCartAdapter(GoPayCartActivity.this, listConfirm);
        listView.setAdapter(shopCartAdapter);


        layout_title_left.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
}
6>:店铺的 ParentShopCartAdapter
public class ParentShopCartAdapter  extends BaseAdapter {


    private Context context ;
    private List<MiddleBean.StoreInfo> listConfirm ;

    double mtempTotalPrice = 0.00;
    int mtempTotalCount = 0 ;


    public ParentShopCartAdapter(Context context , List<MiddleBean.StoreInfo> listConfirm){
        this.context = context ;
        this.listConfirm = listConfirm ;
        Log.e("TAG" , "ParentShopCartAdapter: "+listConfirm.size()) ;
    }

    @Override
    public int getCount() {
        return listConfirm.size();
    }

    @Override
    public Object getItem(int position) {
        return listConfirm.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder;
        if (convertView == null) {
            holder = new Holder();
            convertView = View.inflate(context, R.layout.item_parent_shopcat, null);  //  module_listview_item

            holder.tv_shop_name = (TextView) convertView.findViewById(R.id.tv_shop_name);
            holder.child_shopcat_lv = (MyListView) convertView.findViewById(R.id.child_shopcat_lv);
            holder.tv_total_shop = (TextView) convertView.findViewById(R.id.tv_total_shop);
            holder.tv_price_2 = (TextView) convertView.findViewById(R.id.tv_price_2);
            convertView.setTag(holder);

        } else {
            holder = (Holder) convertView.getTag();
        }

        mtempTotalPrice = 0.00;
        mtempTotalCount = 0;

//        Log.e("TAG" , "getView: "+listConfirm.get(position).getName()) ;

        holder.tv_shop_name.setText(listConfirm.get(position).getName());
        List<MiddleBean.StoreInfo.GoodsInfo> goodses = listConfirm.get(position).getGoodses();
        for (int i = 0; i < goodses.size(); i++) {
            int count = goodses.get(i).getCount();
            double price = goodses.get(i).getPrice();
            mtempTotalCount++;
            mtempTotalPrice += price*count ;
        }
        Log.e("TAG" , "填充数据:mtempTotalCount:"+mtempTotalCount+", mtempTotalPrice:"+mtempTotalPrice) ;
        if (goodses != null && goodses.size() > 0) {
            holder.child_shopcat_lv.setAdapter(new ChildShopCartAdapter(context, listConfirm,goodses));
        }

        holder.tv_total_shop.setText("共"+mtempTotalCount+"件商品");
        holder.tv_price_2.setText(mtempTotalPrice+"");
        return convertView;
    }

    class Holder {
        TextView tv_shop_name,tv_total_shop,tv_price_2 ;
        MyListView child_shopcat_lv ;
    }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,445评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,889评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,047评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,760评论 1 276
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,745评论 5 367
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,638评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,011评论 3 398
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,669评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,923评论 1 299
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,655评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,740评论 1 330
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,406评论 4 320
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,995评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,961评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,197评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,023评论 2 350
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,483评论 2 342

推荐阅读更多精彩内容

  • 前言 下边记录下自己在项目中写的购物车的功能,代码是参照 Android仿淘宝购物车,玩转电商购物车大佬,然后根据...
    世道无情阅读 2,692评论 0 6
  • 关于Mongodb的全面总结 MongoDB的内部构造《MongoDB The Definitive Guide》...
    中v中阅读 31,894评论 2 89
  • 灵感,犹如花儿,多数在夜里悄悄绽放。如折扇般轻轻打开,散发着若有似无的馨香。 我带着欣喜慢慢地靠近,沿着花的脉络肌...
    丫丫18阅读 415评论 4 6
  • 都不给人家留下。像躲害虫一样躲人家,像打过街老鼠一样打压人家!
    ccpjsg阅读 142评论 0 0
  • 80后的中年危机,已经默默拉开帷幕。去参加饭局就能看出来,表面上还是推杯换盏觥筹交错高谈阔论指点江山,但是很显然已...
    刀疤阿姨dede阅读 183评论 2 1