仿京东购物车+订单

//购物车的适配器
public class GoodsAdapter extends BaseExpandableListAdapter {
    private Context context;
    private List<GetCarsBean.DataBean> groupList;
    private List<List<GetCarsBean.DataBean.ListBean>> childList;
    private LayoutInflater inflater;

    public GoodsAdapter(Context context, List<GetCarsBean.DataBean> groupList, List<List<GetCarsBean.DataBean.ListBean>> childList) {
        this.context = context;
        this.groupList = groupList;
        this.childList = childList;
        inflater = LayoutInflater.from(context);
    }

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

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

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

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return childList.get(groupPosition).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, final ViewGroup parent) {
        View view;
        final GroupViewHolder holder;
        if (convertView == null){
            holder = new GroupViewHolder();
            view = inflater.inflate(R.layout.item_parent,null);
            holder.cbGroup = view.findViewById(R.id.check_parent);
            holder.tv_number = view.findViewById(R.id.tv_num);
            view.setTag(holder);
        }else {
            view = convertView;
            holder = (GroupViewHolder) view.getTag();
        }
        final GetCarsBean.DataBean dataBean = groupList.get(groupPosition);
        holder.cbGroup.setChecked(dataBean.isGroupCheck());
        holder.tv_number.setText(dataBean.getSellerName());
        //一级列表点击事件
        holder.cbGroup.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //一级的选中状态
                boolean flag = holder.cbGroup.isChecked();
                //bean类关联
                dataBean.setGroupCheck(flag);
                //调用点击一级的选中改变二级的状态的方法
                setChangChildCheckBoxState(groupPosition,flag);
                //判断是否需要勾选全选按钮(一级的是否全部勾选)
                changAllState(isAllGroupCheckBoxSelected());
                //计算总价
                EventBus.getDefault().post(computerTotal());
                //刷新适配器
                notifyDataSetChanged();
            }
        });
        return view;
    }

    @Override
    public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
        View view;
        final ChildViewHolder holder;
        if (convertView == null) {
            holder = new ChildViewHolder();
            view = inflater.inflate(R.layout.item_child, null);
            holder.tupian = view.findViewById(R.id.tupian);
            holder.cbChild = view.findViewById(R.id.cb_child);
            holder.tv_tel = view.findViewById(R.id.tv_tel);
            holder.tv_content = view.findViewById(R.id.tv_content);
            holder.tv_time = view.findViewById(R.id.tv_time);
            holder.tv_price = view.findViewById(R.id.tv_pri);
            holder.iv_add = view.findViewById(R.id.iv_add);
            holder.iv_del = view.findViewById(R.id.iv_del);
            holder.tv_num = view.findViewById(R.id.tv_num);
            view.setTag(holder);
        } else {
            view = convertView;
            holder = (ChildViewHolder) view.getTag();
        }
        final GetCarsBean.DataBean.ListBean bean = childList.get(groupPosition).get(childPosition);
        String[] split = bean.getImages().split("\\|");
        Glide.with(context).load(split[0]).into(holder.tupian);
        holder.cbChild.setChecked(bean.isChildCheck());
        holder.tv_tel.setText(bean.getTitle().substring(0,15));
        holder.tv_content.setText(bean.getPid()+"");
        holder.tv_time.setText(bean.getCreatetime());
        holder.tv_price.setText(bean.getPrice() + "");
        holder.tv_num.setText(bean.getNum() + "");
        //二级的选中状态
        holder.cbChild.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //获取选是否选中
                boolean flag = holder.cbChild.isChecked();
                //Bean关联
                bean.setChildCheck(flag);
                //判断是否选中和是否全部选中
                if (holder.cbChild.isChecked()) {
                    //当前checkbox是选中状态
                    if (isAllChildCheckBoxSelected(groupPosition)) {
                        setChangGroupCheckBoxState(groupPosition, true);
                        changAllState(isAllGroupCheckBoxSelected());
                    }
                } else {
                    setChangGroupCheckBoxState(groupPosition, false);
                    changAllState(isAllGroupCheckBoxSelected());
                }
                //计算总价并发送
                EventBus.getDefault().post(computerTotal());
                //刷新适配器
                notifyDataSetChanged();
            }
        });
        //加号的点击事件
        holder.iv_add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int num = bean.getNum();
                holder.tv_num.setText(++num+"");
                bean.setNum(num);
                //计算总价并发送
                EventBus.getDefault().post(computerTotal());
                //刷新适配器
                notifyDataSetChanged();
            }
        });
        //减号的点击事件
        holder.iv_del.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int num = bean.getNum();
                if (num==1){
                    Toast.makeText(context,"宝贝不能被在减少了!!!",Toast.LENGTH_SHORT).show();
                    return;
                }
                holder.tv_num.setText(--num+"");
                bean.setNum(num);
                //计算总价并发送
                EventBus.getDefault().post(computerTotal());
                //刷新适配器
                notifyDataSetChanged();
            }
        });
        return view;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return false;
    }
    class GroupViewHolder {
        CheckBox cbGroup;
        TextView tv_number;
    }

    class ChildViewHolder {
        ImageView tupian;
        CheckBox cbChild;
        TextView tv_tel;
        TextView tv_content;
        TextView tv_time;
        TextView tv_price;
        ImageView iv_del;
        ImageView iv_add;
        TextView tv_num;
    }
    /**
     * 一级点击改变二级的状态
     * @param groupPosition
     * @param flag
     */
   private void setChangChildCheckBoxState(int groupPosition,boolean flag){
       List<GetCarsBean.DataBean.ListBean> listBeans = childList.get(groupPosition);
       for (int i = 0; i < listBeans.size(); i++) {
           GetCarsBean.DataBean.ListBean listBean = listBeans.get(i);
           listBean.setChildCheck(flag);
       }
       notifyDataSetChanged();
   }

    /**
     * 二级改变一级的状态
     * @param groupPosition
     * @param flag
     */
    private void setChangGroupCheckBoxState(int groupPosition,boolean flag){
        GetCarsBean.DataBean dataBean = groupList.get(groupPosition);
        dataBean.setGroupCheck(flag);
        notifyDataSetChanged();
    }
    /**
     * 计算总价
     * @return
     */
    private PriceAndCountEvent computerTotal(){
       int count = 0;
       int price = 0;
        for (int i = 0; i < childList.size(); i++) {
            List<GetCarsBean.DataBean.ListBean> listBeans = childList.get(i);
            for (int j = 0; j < listBeans.size(); j++) {
                GetCarsBean.DataBean.ListBean listBean = listBeans.get(j);
                if (listBean.isChildCheck()){
                    count += listBean.getNum();
                    price += listBean.getNum()*listBean.getPrice();
                }
            }
        }
        PriceAndCountEvent event = new PriceAndCountEvent();
        event.setCount(count);
        event.setPrice(price);
        return event;
    }

    /**
     * 判断一级是否全选
     * @return
     */
    private boolean isAllGroupCheckBoxSelected(){
        for (int i = 0; i < groupList.size(); i++) {
            GetCarsBean.DataBean dataBean = groupList.get(i);
            if (!dataBean.isGroupCheck()){
                return false;
            }
        }
        return true;
    }

    /**
     * 判断二级是否全选
     * @param groupPosition
     * @return
     */
    private boolean isAllChildCheckBoxSelected(int groupPosition){
        List<GetCarsBean.DataBean.ListBean> listBeans = childList.get(groupPosition);
        for (int i = 0; i < listBeans.size(); i++) {
            GetCarsBean.DataBean.ListBean listBean = listBeans.get(i);
            if (!listBean.isChildCheck()){
                return false;
            }
        }
        return true;
    }

    /**
     * 改变全选状态
     * @param flag
     */
    private void changAllState(boolean flag){
        MessageEvent messageEvent = new MessageEvent();
        messageEvent.setChecked(flag);
        EventBus.getDefault().post(messageEvent);
    }

    /**
     * 全选反选
     * @param flag
     */
    public void setAll(boolean flag){
        for (int i = 0; i < groupList.size(); i++) {
            setChangGroupCheckBoxState(i,flag);
            setChangChildCheckBoxState(i,flag);
        }
        //计算总价并发送
        EventBus.getDefault().post(computerTotal());
        //刷新适配器
        notifyDataSetChanged();
    }
}


//订单页面适配器
public class OrderAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private Context context;
    private List<GetOrdersBean.DataBean> list = new ArrayList<>();
   private final MainPresenter mainPresenter;

    public OrderAdapter(Context context, List<GetOrdersBean.DataBean> list) {
        this.context = context;
        this.list = list;
        mainPresenter = new MainPresenter();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.order_item, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final GetOrdersBean.DataBean dataBean = list.get(position);
        MyViewHolder myViewHolder = (MyViewHolder) holder;
        myViewHolder.tv_title.setText(dataBean.getTitle());
        int status = dataBean.getStatus();
        if (status == 0) {
            myViewHolder.tv_type.setText("待支付");
            myViewHolder.tv_action.setText("取消订单");
            myViewHolder.tv_type.setTextColor(Color.RED);
        } else if (status == 1) {
            myViewHolder.tv_type.setText("已支付");
            myViewHolder.tv_action.setText("查看订单");
            myViewHolder.tv_type.setTextColor(Color.BLACK);
        } else {
            myViewHolder.tv_type.setText("已取消");
            myViewHolder.tv_action.setText("查看订单");
            myViewHolder.tv_type.setTextColor(Color.BLACK);
        }

        myViewHolder.tv_price.setText("" + dataBean.getPrice());
        myViewHolder.tv_time.setText("" + dataBean.getCreatetime());

        myViewHolder.tv_action.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new AlertDialog.Builder(context)
                        .setTitle("提示")
                        .setMessage("确定取消订单吗?")
                        .setPositiveButton("", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                               mainPresenter.updateOrder(context,dataBean.getStatus()+"", dataBean.getOrderid() + "");
                            }
                        })
                        .setNegativeButton("", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {

                            }
                        })
                        .show();
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }
    class MyViewHolder extends RecyclerView.ViewHolder {

        private final TextView tv_title;
        private final TextView tv_type;
        private final TextView tv_price;
        private final TextView tv_time;
        private final TextView tv_action;

        public MyViewHolder(View itemView) {
            super(itemView);
            tv_title = itemView.findViewById(R.id.order_tvTitle);
            tv_type = itemView.findViewById(R.id.order_tvType);
            tv_price = itemView.findViewById(R.id.order_tvPrice);
            tv_time = itemView.findViewById(R.id.order_tvTime);
            tv_action = itemView.findViewById(R.id.order_tvAction);
        }
    }
}
/**
 * 详情:创建订单的实体类
 */

public class BaseBean {

    /**
     * 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;
    }
}

/**
 * 详情:购物车页面的实体类
 */

public class GetCarsBean {

    /**
     * msg : 请求成功
     * code : 0
     * data : [{"list":[{"bargainPrice":1599,"createtime":"2017-10-14T21:48:08","detailUrl":"https://item.m.jd.com/product/1993026402.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t5863/302/8961270302/97126/41feade1/5981c81cNc1b1fbef.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7003/250/1488538438/195825/53bf31ba/5981c57eN51e95176.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5665/100/8954482513/43454/418611a9/5981c57eNd5fc97ba.jpg!q70.jpg","num":2,"pid":47,"price":111,"pscid":39,"selected":0,"sellerid":3,"subhead":"碳黑色 32GB 全网通 官方标配   1","title":"锤子 坚果Pro 特别版 巧克力色 酒红色 全网通 移动联通电信4G手机 双卡双待 碳黑色 32GB 全网通"}],"sellerName":"商家3","sellerid":"3"},{"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":1,"sellerid":4,"subhead":"【现货新品抢购】全面屏2.0震撼来袭,骁龙835处理器,四曲面陶瓷机","title":"小米(MI) 小米MIX2 手机 黑色 全网通 (6GB+64GB)【标配版】"}],"sellerName":"商家4","sellerid":"4"},{"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":9,"pid":15,"price":233.99,"pscid":1,"selected":0,"sellerid":8,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellerName":"商家8","sellerid":"8"},{"list":[{"bargainPrice":11800,"createtime":"2017-10-03T23:53:28","detailUrl":"https://mitem.jd.hk/ware/view.action?wareId=1988853309&cachekey=1acb07a701ece8d2434a6ae7fa6870a1","images":"https://m.360buyimg.com/n0/jfs/t6130/97/1370670410/180682/1109582a/593276b1Nd81fe723.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5815/178/2614671118/51656/7f52d137/593276c7N107b725a.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5878/60/2557817477/30873/4502b606/593276caN5a7d6357.jpg!q70.jpg","num":12,"pid":71,"price":32999,"pscid":40,"selected":0,"sellerid":15,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP213英寸Bar i5/8G/256G"}],"sellerName":"商家15","sellerid":"15"},{"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"}]
     */

    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":1599,"createtime":"2017-10-14T21:48:08","detailUrl":"https://item.m.jd.com/product/1993026402.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t5863/302/8961270302/97126/41feade1/5981c81cNc1b1fbef.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7003/250/1488538438/195825/53bf31ba/5981c57eN51e95176.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5665/100/8954482513/43454/418611a9/5981c57eNd5fc97ba.jpg!q70.jpg","num":2,"pid":47,"price":111,"pscid":39,"selected":0,"sellerid":3,"subhead":"碳黑色 32GB 全网通 官方标配   1","title":"锤子 坚果Pro 特别版 巧克力色 酒红色 全网通 移动联通电信4G手机 双卡双待 碳黑色 32GB 全网通"}]
         * sellerName : 商家3
         * sellerid : 3
         */

        private String sellerName;
        private String sellerid;
        private List<ListBean> list;
        private boolean isGroupCheck;

        public String getSellerName() {
            return sellerName;
        }

        public boolean isGroupCheck() {
            return isGroupCheck;
        }

        public void setGroupCheck(boolean groupCheck) {
            isGroupCheck = groupCheck;
        }

        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 : 1599.0
             * createtime : 2017-10-14T21:48:08
             * detailUrl : https://item.m.jd.com/product/1993026402.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends
             * images : https://m.360buyimg.com/n0/jfs/t5863/302/8961270302/97126/41feade1/5981c81cNc1b1fbef.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7003/250/1488538438/195825/53bf31ba/5981c57eN51e95176.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5665/100/8954482513/43454/418611a9/5981c57eNd5fc97ba.jpg!q70.jpg
             * num : 2
             * pid : 47
             * price : 111.0
             * pscid : 39
             * selected : 0
             * sellerid : 3
             * subhead : 碳黑色 32GB 全网通 官方标配   1             * title : 锤子 坚果Pro 特别版 巧克力色 酒红色 全网通 移动联通电信4G手机 双卡双待 碳黑色 32GB 全网通
             */

            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;
            private boolean isChildCheck;

            public double getBargainPrice() {
                return bargainPrice;
            }

            public boolean isChildCheck() {
                return isChildCheck;
            }

            public void setChildCheck(boolean childCheck) {
                isChildCheck = childCheck;
            }

            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;
            }
        }
    }
}

/**
 * 详情:订单数据展示的实体类
 */

public class GetOrdersBean {

    /**
     * msg : 请求成功
     * code : 0
     * data : [{"createtime":"2017-10-22T15:14:39","orderid":890,"price":11800,"status":0,"title":"","uid":71},{"createtime":"2017-11-09T09:20:58","orderid":1447,"price":567,"status":0,"title":"订单标题测试","uid":71},{"createtime":"2017-11-09T09:20:58","orderid":1449,"price":399,"status":0,"title":"订单标题测试","uid":71},{"createtime":"2017-12-11T19:11:33","orderid":3344,"price":99.99,"status":0,"title":null,"uid":71},{"createtime":"2017-12-11T20:13:52","orderid":3345,"price":99.99,"status":0,"title":null,"uid":71},{"createtime":"2017-12-11T20:58:31","orderid":3346,"price":99.99,"status":0,"title":null,"uid":71},{"createtime":"2017-12-12T14:14:48","orderid":3349,"price":99.99,"status":0,"title":null,"uid":71},{"createtime":"2017-12-12T14:14:48","orderid":3350,"price":99.99,"status":0,"title":null,"uid":71},{"createtime":"2017-12-12T14:14:48","orderid":3351,"price":99.99,"status":0,"title":null,"uid":71},{"createtime":"2017-12-13T20:29:14","orderid":3371,"price":99.99,"status":0,"title":null,"uid":71}]
     * page : 1
     */

    private String msg;
    private String code;
    private String page;
    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 String getPage() {
        return page;
    }

    public void setPage(String page) {
        this.page = page;
    }

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

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

    public static class DataBean {
        /**
         * createtime : 2017-10-22T15:14:39
         * orderid : 890
         * price : 11800.0
         * status : 0
         * title :
         * uid : 71
         */

        private String createtime;
        private int orderid;
        private double price;
        private int status;
        private String title;
        private int uid;

        public String getCreatetime() {
            return createtime;
        }

        public void setCreatetime(String createtime) {
            this.createtime = createtime;
        }

        public int getOrderid() {
            return orderid;
        }

        public void setOrderid(int orderid) {
            this.orderid = orderid;
        }

        public double getPrice() {
            return price;
        }

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

        public int getStatus() {
            return status;
        }

        public void setStatus(int status) {
            this.status = status;
        }

        public String getTitle() {
            return title;
        }

        public void setTitle(String title) {
            this.title = title;
        }

        public int getUid() {
            return uid;
        }

        public void setUid(int uid) {
            this.uid = uid;
        }
    }
}

/**
 * 详情:全选反选eventbus
 */
public class MessageEvent {
    private boolean checked;

    public boolean isChecked() {
        return checked;
    }

    public void setChecked(boolean checked) {
        this.checked = checked;
    }
}


 /** * 详情:钱和数量的eventbus
 */
public class PriceAndCountEvent {
    private int price;
    private int count;

    public int getPrice() {
        return price;
    }

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

    public int getCount() {
        return count;
    }

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


/**
 * 详情:Model层中的接口
 */

public interface IMainModel {
    //获取购物车信息
    void getGoodsCar(Map<String,String> params, OnNetWorkListener<GetCarsBean> onNetWorkListener);
    //创建订单
    void createOrder(Map<String,String> params, OnNetWorkListener<BaseBean> onNetWorkListener);
    //显示订单
    void getOrders(Map<String,String> params, OnNetWorkListener<GetOrdersBean> onNetWorkListener);
    //修改订单
    void updateOrder(Map<String,String> params, OnNetWorkListener<BaseBean> onNetWorkListener);
}


/**
 * 详情:model层中的方法  真正的网络请求
 */

public class MainModel implements IMainModel{
    //创建Handler
    private Handler handler = new Handler(Looper.getMainLooper());

    /**
     * 购物车数据展示
     * @param params
     * @param onNetWorkListener
     */
    @Override
    public void getGoodsCar(Map<String, String> params, final OnNetWorkListener<GetCarsBean> onNetWorkListener) {
        //网络请求
        HttpUtils.getHttpUtils().doPost(Api.GETCARS, params, new Callback() {
            @Override
            public void onFailure(Call call, final IOException e) {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        //失败的回调
                        onNetWorkListener.onFailure(e);
                    }
                });

            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String string = response.body().string();
                final GetCarsBean getCarsBean = new Gson().fromJson(string, GetCarsBean.class);
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        //成功的回调
                        onNetWorkListener.onSucceed(getCarsBean);
                    }
                });
            }
        });
    }

    /**
     * 创建订单
     * @param params
     * @param onNetWorkListener
     */
    @Override
    public void createOrder(Map<String, String> params, final OnNetWorkListener<BaseBean> onNetWorkListener) {
        HttpUtils.getHttpUtils().doPost(Api.CREATEORDER, params, new Callback() {
            @Override
            public void onFailure(Call call, final IOException e) {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        //失败的回调
                        onNetWorkListener.onFailure(e);
                    }
                });
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String string = response.body().string();
                final BaseBean createOrderBean = new Gson().fromJson(string, BaseBean.class);
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        //成功的回调
                        onNetWorkListener.onSucceed(createOrderBean);
                    }
                });
            }
        });
    }

    /**
     * 订单数据展示
     * @param params
     * @param onNetWorkListener
     */
    @Override
    public void getOrders(Map<String, String> params, final OnNetWorkListener<GetOrdersBean> onNetWorkListener) {
        HttpUtils.getHttpUtils().doPost(Api.GETORDERS, params, new Callback() {
            @Override
            public void onFailure(Call call, final IOException e) {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        //失败的回调
                        onNetWorkListener.onFailure(e);
                    }
                });
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String string = response.body().string();
                final GetOrdersBean getOrdersBean = new Gson().fromJson(string, GetOrdersBean.class);
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        //成功的回调
                       onNetWorkListener.onSucceed(getOrdersBean);
                }
                });
            }
        });
    }

    /**
     * 修改订单
     * @param params
     * @param onNetWorkListener
     */
    @Override
    public void updateOrder(Map<String, String> params, final OnNetWorkListener<BaseBean> onNetWorkListener) {
        HttpUtils.getHttpUtils().doPost(Api.GETORDERS, params, new Callback() {
            @Override
            public void onFailure(Call call, final IOException e) {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        //失败的回调
                        onNetWorkListener.onFailure(e);
                    }
                });
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String string = response.body().string();
                final BaseBean baseBean = new Gson().fromJson(string, BaseBean.class);
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        //成功的回调
                      onNetWorkListener.onSucceed(baseBean);
                    }
                });
            }
        });
    }
}
 

/**
 * 详情:所用的所有接口
 */

public interface Api {
    //获得购物车的接口
    public static final String GETCARS = "https://www.zhaoapi.cn/product/getCarts";
    //创建订单接口
    public static final String CREATEORDER = "https://www.zhaoapi.cn/product/createOrder";
    //获取订单列表接口
    public static final String GETORDERS = "https://www.zhaoapi.cn/product/getOrders";
    //.修改订单状态
    public static final String UPDATEORDER = "https://www.zhaoapi.cn/product/updateOrder";
}

/**
 * 详情:OK的工具类
 */
public class HttpUtils {
    private static volatile HttpUtils httpUtils;
    private OkHttpClient okHttpClient;

    private HttpUtils() {
        //创建OKhttpClient和拦截器
       // HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
        //logging.setLevel(HttpLoggingInterceptor.Level.BODY);
        okHttpClient = new OkHttpClient.Builder()
                .addInterceptor(new LoggingInterceptor())
                .build();
    }
    //单例模式
    public static HttpUtils getHttpUtils(){
        if (httpUtils == null){
            synchronized (HttpUtils.class){
                if (httpUtils == null){
                    httpUtils = new HttpUtils();
                }
            }
        }
        return httpUtils;
    }
    //Get
    public void doGet(String url, Callback callback){
        //此处应该放置判断网络
        Request request = new Request.Builder().url(url).get().build();
        okHttpClient.newCall(request).enqueue(callback);
    }
    //post
    public void doPost(String url, Map<String,String> params, Callback callback){
        //此处应该放置判断网络
        //判断参数
        if (params == null ||params.size() == 0){
            throw new RuntimeException("params is null!!!");
        }
        FormBody.Builder builder = new FormBody.Builder();
        for (Map.Entry<String,String> entry:params.entrySet()){
            builder.add(entry.getKey(),entry.getValue());
        }
        FormBody formBody = builder.build();
        Request request = new Request.Builder()
                .url(url)
                .post(formBody)
                .build();
        okHttpClient.newCall(request).enqueue(callback);
    }
}

/**
 * 详情:自定义拦截器
 */
public class LoggingInterceptor implements Interceptor {
    //POST自定义拦截器
    @Override
    public Response intercept(Chain chain) throws IOException {
        Request original = chain.request();
        HttpUrl url=original.url().newBuilder()
                .addQueryParameter("source","android")
                .build();
        //添加请求头
        Request request = original.newBuilder()
                .url(url)
                .build();
        return chain.proceed(request);
    }
}

 

/**
 * 详情:成功失败的回调
 */

public interface OnNetWorkListener<T> {
    //失败的回调
    void onFailure(Exception e);
    //成功的回调
    void onSucceed(T t);
}



 

/**
 * 详情:presenter层
 */

public class MainPresenter {
    private IMainActivity iMainActivity;
    private IMainModel iMainModel;
    private IOrderActivity iOrderActivity;

    /**
     * 购物车页面
     * @param iMainActivity
     */
    public MainPresenter(IMainActivity iMainActivity) {
        this.iMainActivity = iMainActivity;
        iMainModel = new MainModel();
    }

    /**
     * 订单页面
     * @param iOrderActivity
     */
    public MainPresenter(IOrderActivity iOrderActivity) {
        this.iOrderActivity = iOrderActivity;
        iMainModel = new MainModel();
    }

    /**
     * 修改订单
     */
    public MainPresenter() {
        this.iMainModel = new MainModel();
    }
    /**
     * 加载购物车
     */
    public void getCarts(){
        HashMap<String, String> params = new HashMap<>();
        params.put("uid","1775");
        iMainModel.getGoodsCar(params, new OnNetWorkListener<GetCarsBean>() {
            @Override
            public void onFailure(Exception e) {

            }

            @Override
            public void onSucceed(GetCarsBean getCarsBean) {
                if (iMainActivity != null) {
                    List<GetCarsBean.DataBean> data = getCarsBean.getData();
                    ArrayList<List<GetCarsBean.DataBean.ListBean>> childList = new ArrayList<>();
                    for (int i = 0; i < data.size(); i++) {
                        List<GetCarsBean.DataBean.ListBean> datas = data.get(i).getList();
                        childList.add(datas);
                    }
                    iMainActivity.showList(data, childList);
                }
            }
        });
    }

    /**
     * 创建订单
     * @param price
     */
    public void createOrder(String price){
        HashMap<String, String> params = new HashMap<>();
        params.put("uid","71");
        params.put("price",price);
        iMainModel.createOrder(params, new OnNetWorkListener<BaseBean>() {
            @Override
            public void onFailure(Exception e) {

            }

            @Override
            public void onSucceed(BaseBean createOrderBean) {
                if (iMainActivity != null) {
                    iMainActivity.showCreateOrder(createOrderBean);
                }
            }
        });
    }

    /**
     * 订单数据展示
     */
    public void getOrders(String status){
        HashMap<String, String> params = new HashMap<>();
        params.put("uid","71");
        if (status != null){
            params.put("status",status);
        }
        iMainModel.getOrders(params, new OnNetWorkListener<GetOrdersBean>() {
            @Override
            public void onFailure(Exception e) {

            }

            @Override
            public void onSucceed(GetOrdersBean getOrdersBean) {
                if (iOrderActivity != null) {
                    iOrderActivity.showOrder(getOrdersBean.getData());
                }
            }
        });
    }

    /***
     * 修改订单
     * @param status
     * @param orderId
     */
    public void updateOrder(final Context context, String status, String orderId){
        HashMap<String, String> params = new HashMap<>();
        params.put("uid","71");
        params.put("status",status);
        params.put("orderId",orderId);
        iMainModel.updateOrder(params, new OnNetWorkListener<BaseBean>() {
            @Override
            public void onFailure(Exception e) {

            }

            @Override
            public void onSucceed(BaseBean baseBean) {
                Toast.makeText(context,baseBean.getMsg(),Toast.LENGTH_SHORT);
            }
        });
    }
    /**
     * 销毁
     */
    public void onDeath(){
        iMainActivity = null;
        iOrderActivity = null;
    }
}



/**
 * 详情:V层的购物车接口
 */

public interface IMainActivity {
    //显示购物车的信息
    public void showList(List<GetCarsBean.DataBean> groupList, List<List<GetCarsBean.DataBean.ListBean>> childList);
    //显示创建订单
    public void showCreateOrder(BaseBean createOrderBean);
}


/**
 * 详情:V层的订单详情接口
 */

public interface IOrderActivity {
    //显示订单数据
    public void showOrder(List<GetOrdersBean.DataBean> beanList);
}

//MainActivity主界面
public class MainActivity extends AppCompatActivity implements View.OnClickListener, IMainActivity {

    private ExpandableListView mElv;
    private CheckBox mCheckAll;
    /**
     * 合计:0
     */
    private TextView mPriceAll;
    /**
     * 结算:0
     */
    private TextView mCountAll;
    private MainPresenter mainPresenter;
    private GoodsAdapter goodsAdapter;
    private ImageView mIvBack;
    private int price;
    private int count;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        mainPresenter = new MainPresenter(this);
        mainPresenter.getCarts();
        EventBus.getDefault().register(this);
    }

    private void initView() {
        mElv = (ExpandableListView) findViewById(R.id.elv);
        mCheckAll = (CheckBox) findViewById(R.id.checkAll);
        mPriceAll = (TextView) findViewById(R.id.priceAll);
        mCountAll = (TextView) findViewById(R.id.countAll);
        mCheckAll.setOnClickListener(this);
        mPriceAll.setOnClickListener(this);
        mIvBack = (ImageView) findViewById(R.id.ivBack);
        mIvBack.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.checkAll:
                goodsAdapter.setAll(mCheckAll.isChecked());
                break;
            case R.id.priceAll:
                mainPresenter.createOrder(price+"");
                break;
            case R.id.ivBack:
                this.finish();
                break;
        }
    }

    @Override
    public void showList(List<GetCarsBean.DataBean> groupList, List<List<GetCarsBean.DataBean.ListBean>> childList) {
        goodsAdapter = new GoodsAdapter(this, groupList, childList);
        mElv.setAdapter(goodsAdapter);
        mElv.setGroupIndicator(null);
        //默认让其全部展开
        for (int i = 0; i < groupList.size(); i++) {
            mElv.expandGroup(i);
        }
    }

    @Override
    public void showCreateOrder(BaseBean createOrderBean) {
        Toast.makeText(MainActivity.this,createOrderBean.getMsg(),Toast.LENGTH_SHORT).show();
        if (createOrderBean.getCode().equals("0")) {
            Intent intent = new Intent(MainActivity.this, OrderActivity.class);
            startActivity(intent);
        }
    }

    /**
     * 销毁
     */
    @Override
    protected void onDestroy() {
        super.onDestroy();
        mainPresenter.onDeath();
        EventBus.getDefault().unregister(this);
    }

    @Subscribe
    public void onMessageEvent(MessageEvent event) {
        mCheckAll.setChecked(event.isChecked());
    }

    @Subscribe
    public void onMessageEvent(PriceAndCountEvent event) {
        price = event.getPrice();
        count = event.getCount();
        mCountAll.setText("合计:" + count);
        mPriceAll.setText("结算:" + price);
    }
}

//订单详情页面
public class OrderActivity extends AppCompatActivity implements View.OnClickListener ,IOrderActivity{

    private ImageView mIvType;
    /**
     * 待支付
     */
    private TextView mDaizhifu;
    /**
     * 已支付
     */
    private TextView mYizhifu;
    /**
     * 已取消
     */
    private TextView mYiquxiao;
    private RecyclerView mRv;
    private MainPresenter mainPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order);
        initView();
        mainPresenter = new MainPresenter(this);
        mainPresenter.getOrders("0");
    }

    private void initView() {
        mIvType = (ImageView) findViewById(R.id.ivType);
        mIvType.setOnClickListener(this);
        mDaizhifu = (TextView) findViewById(R.id.daizhifu);
        mDaizhifu.setOnClickListener(this);
        mYizhifu = (TextView) findViewById(R.id.yizhifu);
        mYizhifu.setOnClickListener(this);
        mYiquxiao = (TextView) findViewById(R.id.yiquxiao);
        mYiquxiao.setOnClickListener(this);
        mRv = (RecyclerView) findViewById(R.id.rv);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ivType:
                //弹出popupwindow
                View view = View.inflate(OrderActivity.this, R.layout.pop_item, null);
                TextView tv1 = view.findViewById(R.id.tv1);
                TextView tv2 = view.findViewById(R.id.tv2);
                TextView tv3 = view.findViewById(R.id.tv3);
                LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                PopupWindow popupWindow = new PopupWindow(view, layoutParams.width, layoutParams.height);
                popupWindow.showAsDropDown(mIvType, 0, 30);
                tv1.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toast.makeText(OrderActivity.this, "tv1", Toast.LENGTH_SHORT).show();
                        mainPresenter.getOrders("0");
                    }
                });
                tv2.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toast.makeText(OrderActivity.this, "tv2", Toast.LENGTH_SHORT).show();
                        mainPresenter.getOrders("1");
                    }
                });
                tv3.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toast.makeText(OrderActivity.this, "tv3", Toast.LENGTH_SHORT).show();
                        mainPresenter.getOrders("2");
                    }
                });
                break;
            case R.id.daizhifu:
                mainPresenter.getOrders("0");
                break;
            case R.id.yizhifu:
                mainPresenter.getOrders("1");
                break;
            case R.id.yiquxiao:
                mainPresenter.getOrders("2");
                break;
        }
    }

    @Override
    public void showOrder(List<GetOrdersBean.DataBean> beanList) {
        mRv.setLayoutManager(new LinearLayoutManager(this));
        OrderAdapter orderAdapter = new OrderAdapter(OrderActivity.this, beanList);
        mRv.setAdapter(orderAdapter);
    }

    /**
     * 销毁
     */
    @Override
    protected void onDestroy() {
        super.onDestroy();
        mainPresenter.onDeath();
    }
}

//MainActivity布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:orientation="vertical">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <ImageView
            android:id="@+id/ivBack"
            android:layout_gravity="center_vertical"
            android:background="@drawable/icon_back"
            android:layout_width="20dp"
            android:layout_height="20dp" />
    <TextView
        android:layout_weight="1"
        android:gravity="center_horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#ff3360"
        android:textSize="20dp"
        android:textColor="#fff"
        android:text="购物车" />
    </LinearLayout>
    <ExpandableListView
        android:id="@+id/elv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"/>
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="#ff3360"
        android:gravity="center_vertical">
        <CheckBox
            android:id="@+id/checkAll"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20px"
            android:layout_centerVertical="true"
            android:background="#fff"
            android:focusable="false"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="50sp"
            android:layout_centerVertical="true"
            android:textSize="20sp"
            android:textColor="#fff"
            android:background="#ff3660"
            android:gravity="center_vertical"
            android:layout_marginLeft="10px"
            android:layout_toRightOf="@+id/checkAll"
            android:text="全选"/>
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:paddingLeft="150dp"
            android:layout_centerVertical="true">
            <TextView
                android:paddingRight="100dp"
                android:id="@+id/countAll"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="20sp"
                android:textColor="#fff"
                android:background="#ff3660"
                android:text="合计:0"/>
            <TextView
                android:id="@+id/priceAll"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="20sp"
                android:textColor="#fff"
                android:background="#ff3660"
                android:text="结算:0"/>
        </LinearLayout>
    </RelativeLayout>
</LinearLayout>


//activity_order.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:orientation="vertical"
    tools:context="com.bwie.hanshuaishuai1510d20171221.view.OrderActivity">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    <TextView
        android:layout_weight="1"
        android:text="订单列表"
        android:textSize="25sp"
        android:gravity="center_horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
        <ImageView
            android:id="@+id/ivType"
            android:layout_width="25dp"
            android:layout_height="25dp"
            android:background="@drawable/lv_icon"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:id="@+id/daizhifu"
            android:textSize="20sp"
            android:gravity="center"
            android:text="待支付"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="wrap_content" />
        <TextView
            android:id="@+id/yizhifu"
            android:textSize="20sp"
            android:gravity="center"
            android:text="已支付"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="wrap_content" />
        <TextView
            android:id="@+id/yiquxiao"
            android:textSize="20sp"
            android:gravity="center"
            android:text="已取消"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="wrap_content" />
    </LinearLayout>
    <android.support.v7.widget.RecyclerView
        android:id="@+id/rv"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </android.support.v7.widget.RecyclerView>
</LinearLayout>


//item_child.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="@android:color/darker_gray"
    android:gravity="center_vertical"
    android:orientation="horizontal">

    <CheckBox
        android:id="@+id/cb_child"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="30dp"
        android:layout_marginLeft="40dp"
        android:layout_marginTop="30dp"
        android:focusable="false" />
    <ImageView
        android:id="@+id/tupian"
        android:background="@mipmap/ic_launcher"
        android:layout_width="30dp"
        android:layout_height="30dp" />
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <TextView
            android:id="@+id/tv_tel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:text="iphone6" />

        <TextView
            android:id="@+id/tv_content"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:text="什么手机" />

        <TextView
            android:id="@+id/tv_time"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:text="2016-12-10" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="vertical">

        <TextView
            android:id="@+id/tv_pri"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"

            android:text="¥3000.00" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="end">

            <ImageView
                android:id="@+id/iv_del"
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:src="@drawable/shopcart_minus_red" />

            <TextView
                android:id="@+id/tv_num"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:background="@drawable/shopcart_add_btn"
                android:paddingBottom="2dp"
                android:paddingLeft="20dp"
                android:paddingRight="20dp"
                android:paddingTop="2dp"
                android:text="1" />

            <ImageView
                android:id="@+id/iv_add"
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:layout_marginLeft="5dp"
                android:src="@drawable/shopcart_add_red" />
        </LinearLayout>
    </LinearLayout>
</LinearLayout>


//item_parent.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:gravity="center_vertical"
    android:layout_height="100dp">
    <CheckBox
        android:id="@+id/check_parent"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:focusable="false"
        android:layout_margin="30dp"/>
    <TextView
        android:id="@+id/tv_sign"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="标记"
        android:paddingRight="20dp"/>
    <TextView
        android:id="@+id/tv_num"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="888888"/>
</LinearLayout>


//order_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:orientation="vertical"
    android:layout_height="100dp">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="33dp">
    <TextView
        android:layout_weight="2"
        android:layout_gravity="center_vertical"
        android:gravity="center"
        android:text="这是商品名称"
        android:id="@+id/order_tvTitle"
        android:layout_width="0dp"
        android:layout_height="wrap_content" />
        <TextView
            android:layout_gravity="center_vertical"
            android:gravity="center"
            android:layout_weight="1"
            android:text="这是支付状态"
            android:id="@+id/order_tvType"
            android:layout_width="0dp"
            android:layout_height="wrap_content" />
    </LinearLayout>
    <TextView
        android:layout_gravity="center_vertical"
        android:gravity="center"
        android:text="这是支付价格"
        android:id="@+id/order_tvPrice"
        android:layout_width="match_parent"
        android:layout_height="33dp" />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="33dp">
        <TextView
            android:layout_weight="2"
            android:layout_gravity="center_vertical"
            android:gravity="center"
            android:text="这是订单时间"
            android:id="@+id/order_tvTime"
            android:layout_width="0dp"
            android:layout_height="wrap_content" />
        <TextView
            android:layout_gravity="center_vertical"
            android:gravity="center"
            android:layout_weight="1"
            android:text="这是操作"
            android:id="@+id/order_tvAction"
            android:layout_width="0dp"
            android:layout_height="wrap_content" />
    </LinearLayout>
</LinearLayout>

//pop_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="wrap_content"
    android:background="#ffffff"
    android:orientation="vertical">

    <TextView
        android:id="@+id/tv1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="待支付"></TextView>

    <TextView
        android:id="@+id/tv2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="已支付"></TextView>

    <TextView
        android:id="@+id/tv3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="已取消"></TextView>
</LinearLayout>

阅读更多
上一篇Timer定时器的基本使用
下一篇RxJava+Retrofit工具类
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭