RecyclerView嵌套RecyclerView来实现购物车页面

一.效果图


RecyclerView嵌套RecyclerView来实现购物车页面_第1张图片
QQ图片20180411103827.png
RecyclerView嵌套RecyclerView来实现购物车页面_第2张图片
QQ图片20180411104159.png

1.UI布局




    

        

        
    

    

    

        

            

        

    

    

        

        

            

                

                
            

            

        

        

    

    



Activity 的代码

package view.dome.com.shoppingcartdome;

import android.app.Dialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.google.gson.Gson;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.List;
import view.dome.com.shoppingcartdome.adapter.ShoppingCartAdapter;
import view.dome.com.shoppingcartdome.bean.ShoppingBean;
import view.dome.com.shoppingcartdome.bean.UpdataButton;
import view.dome.com.shoppingcartdome.utils.CommomDialog;


public class MainActivity extends AppCompatActivity implements ShoppingCartAdapter.OnRecyclerViewItemClickListener, View.OnClickListener, ShoppingCartAdapter.OndeleteidClickListener {

    private CheckBox tvShopCartSelect;
    private TextView tvShopCartTotalPrice;
    private ImageView mBock_return;
    private RecyclerView rlvShopCart;
    private TextView tvShopCartSubmit;
    private ShoppingBean shopCartBeans;
    private List data;
    private ShoppingCartAdapter mallShopCartAdapter;
    boolean isselect = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initData();
        initListener();
    }

    private void initListener() {
        mBock_return.setOnClickListener(this);
        tvShopCartSelect.setOnClickListener(this);
        tvShopCartSubmit.setOnClickListener(this);
    }

    /**
     *  设置数据
     */
    private void initData() {
        //测试用的数据转换成实体类,赋值到adapter中
        String jsonData="{\"status\":true,\"msg\":\"\",\"data\":[{\"store_name\":\"微超优品\",\"user_id\":\"229\",\"store_id\":\"14828331510902860000\",\"list\":[{\"goods_price\":183,\"cart_id\":\"15232812841628050000\",\"user_id\":\"229\",\"member_id\":\"15222940696559300000\",\"goods_id\":\"15162475454444720000\",\"goods_num\":\"1\",\"goods_name\":\"飞科FC5901专业发廊理发器电推剪电动推子成人老人儿童剃头\",\"goods_image\":\"http://img.lion-mall.com/goods/20180118/dbff92fc8dee4e26c39b21ee207a18a8.jpg\",\"spec_desc\":\"\",\"spec1_name\":\"型号\",\"spec1_value\":\"FC5901(积分价)\",\"spec2_name\":\"\",\"spec2_value\":\"\",\"proportion_return\":\"50\",\"goods_points\":66,\"is_have_point\":\"1\",\"model_id\":\"15162475454434460000\"}]},{\"store_name\":\"本港海产\",\"user_id\":\"3096\",\"store_id\":\"15132364355633290000\",\"list\":[{\"goods_price\":33,\"cart_id\":\"15232812763901580000\",\"user_id\":\"3096\",\"member_id\":\"15222940696559300000\",\"goods_id\":\"15156635008014120000\",\"goods_num\":\"1\",\"goods_name\":\"本港海产 即食大片海苔原味辣味125g包邮\",\"goods_image\":\"http://img.lion-mall.com/goods/20180111/65aae13eb49e93939850c707dbf69966.jpg\",\"spec_desc\":\"\",\"spec1_name\":\"规格\",\"spec1_value\":\"1*125g(积分价)\",\"spec2_name\":\"\",\"spec2_value\":\"\",\"proportion_return\":\"50\",\"goods_points\":7,\"is_have_point\":\"1\",\"model_id\":\"15156635008003640000\"}]},{\"store_name\":\"智能生活屋\",\"user_id\":\"3090\",\"store_id\":\"15110923292896270000\",\"list\":[{\"goods_price\":98,\"cart_id\":\"15232812214585490000\",\"user_id\":\"3090\",\"member_id\":\"15222940696559300000\",\"goods_id\":\"15154810744781680000\",\"goods_num\":\"1\",\"goods_name\":\"杜酷(DUKU) 无线蓝牙键盘多屏双通道蓝牙键盘通用\",\"goods_image\":\"http://img.lion-mall.com/goods/20180109/8885a44d743b75ccb0f3601686ddb719.jpg\",\"spec_desc\":\"\",\"spec1_name\":\"颜色\",\"spec1_value\":\"金色(积分价)\",\"spec2_name\":\"\",\"spec2_value\":\"\",\"proportion_return\":\"50\",\"goods_points\":31,\"is_have_point\":\"1\",\"model_id\":\"15154810744751190000\"}]},{\"store_name\":\"聚美佳品\",\"user_id\":\"2985\",\"store_id\":\"15028511939255260000\",\"list\":[{\"goods_price\":48,\"cart_id\":\"15232475994654440000\",\"user_id\":\"2985\",\"member_id\":\"15222940696559300000\",\"goods_id\":\"15153090695659930000\",\"goods_num\":\"2\",\"goods_name\":\"卡通抱枕被子两用 多功能暖手汽车空调被三合一\",\"goods_image\":\"http://img.lion-mall.com/goods/20180107/568058f3aaf01cd0297b26d75c1ff85a.png\",\"spec_desc\":\"\",\"spec1_name\":\"颜色\",\"spec1_value\":\"可爱猫\",\"spec2_name\":\"\",\"spec2_value\":\"\",\"proportion_return\":\"50\",\"goods_points\":0,\"is_have_point\":\"1\",\"model_id\":\"15153090695654650000\"}]},{\"store_name\":\"羽森家纺\",\"user_id\":\"267\",\"store_id\":\"14830180850588560000\",\"list\":[{\"goods_price\":380,\"cart_id\":\"15232475900203700000\",\"user_id\":\"267\",\"member_id\":\"15222940696559300000\",\"goods_id\":\"15155019232807690000\",\"goods_num\":\"1\",\"goods_name\":\"羽森高档双层纱贡缎阳绒四件套\",\"goods_image\":\"http://img.lion-mall.com/goods/20180109/7de0db542473faf6659ed457dda87275.jpg\",\"spec_desc\":\"\",\"spec1_name\":\"颜色\",\"spec1_value\":\"蒙特城堡(香槟灰)\",\"spec2_name\":\"规格\",\"spec2_value\":\"200*230\",\"proportion_return\":\"50\",\"goods_points\":0,\"is_have_point\":\"1\",\"model_id\":\"15155019232792440000\"}]},{\"store_name\":\"戈勒世家\",\"user_id\":\"1098\",\"store_id\":\"14879242960201500000\",\"list\":[{\"goods_price\":67,\"cart_id\":\"15232475545649120000\",\"user_id\":\"1098\",\"member_id\":\"15222940696559300000\",\"goods_id\":\"15168503821784490000\",\"goods_num\":\"2\",\"goods_name\":\"男士特色独眼怪兽胸包单肩包斜挎包时尚户外休闲包潮流男包\",\"goods_image\":\"http://img.lion-mall.com/goods/20180125/a355d78946c721565d2e44687f15f934.jpg\",\"spec_desc\":\"\",\"spec1_name\":\"颜色\",\"spec1_value\":\"黑色(积分兑)\",\"spec2_name\":\"\",\"spec2_value\":\"\",\"proportion_return\":\"50\",\"goods_points\":12,\"is_have_point\":\"1\",\"model_id\":\"15168503821773910000\"},{\"goods_price\":82,\"cart_id\":\"15232475436635450000\",\"user_id\":\"1098\",\"member_id\":\"15222940696559300000\",\"goods_id\":\"15168478480459580000\",\"goods_num\":\"1\",\"goods_name\":\"男士手提包AD18单肩包斜挎皮包商务公文包手提包\",\"goods_image\":\"http://img.lion-mall.com/goods/20180125/31966da605420f672712bd07a36dcd4a.jpg\",\"spec_desc\":\"\",\"spec1_name\":\"颜色\",\"spec1_value\":\"黑色(积分兑)\",\"spec2_name\":\"\",\"spec2_value\":\"\",\"proportion_return\":\"50\",\"goods_points\":23,\"is_have_point\":\"1\",\"model_id\":\"15168478480445350000\"}]}]}";
                Gson gson = new Gson();
      shopCartBeans =gson.fromJson(jsonData,ShoppingBean.class);
           data =null;
           data =shopCartBeans.getData();
        if(mallShopCartAdapter !=null){
            mallShopCartAdapter.setmDatas(data);
            mallShopCartAdapter.notifyDataSetChanged();
        }else {
            mallShopCartAdapter =new ShoppingCartAdapter(this,data);
            rlvShopCart.setLayoutManager(new LinearLayoutManager(MainActivity.this,LinearLayoutManager.VERTICAL,false));
            rlvShopCart.setAdapter(mallShopCartAdapter);
            mallShopCartAdapter.setOnItemClickListener(this);
            mallShopCartAdapter.setOndeleteidClickListener(this); //删除的点击
        }
    }

    /**
     *  初始化控件
     */
    private void initView() {
        tvShopCartSelect = (CheckBox) findViewById(R.id.tv_shopcart_addselect); //全选
        tvShopCartTotalPrice = (TextView) findViewById(R.id.tv_shopcart_totalprice); //总价
        mBock_return = (ImageView)findViewById(R.id.bock_return); //返回
        rlvShopCart = (RecyclerView) findViewById(R.id.rlv_shopcart);//RecycleView
        tvShopCartSubmit = (TextView) findViewById(R.id.tv_shopcart_submit); //去结算
        //注册事件
        EventBus.getDefault().register(this);
    }


    @Override
    public void onItemClick(View view, ShoppingBean.DataBean data) {

    }

    //这里用了eventBus来进行实时价格的UI更改。
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void messageEventBus(UpdataButton event){
        //刷新UI
        tvShopCartTotalPrice.setText("结算(¥" + event.getDiscribe() + ")");
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }



    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.bock_return: //返回
                finish();
                break;
            case R.id.tv_shopcart_addselect: //全选
                if (isselect) {
                    tvShopCartSelect.setChecked(false);
                    isselect = false;
                    mallShopCartAdapter.setAllselect(false);
                } else {
                    tvShopCartSelect.setChecked(true);
                    isselect = true;
                    mallShopCartAdapter.setAllselect(true);
                }
                break;

            case R.id.tv_shopcart_submit:
          Toast.makeText(MainActivity.this,"被wwwwfsadsadd",Toast.LENGTH_SHORT).show();
                break;
        }
    }

    /**
     *  删除的点击事件
     * @param view
     * @param id
     */
    @Override
    public void onIdClick(View view, String id) {
        new CommomDialog(MainActivity.this, R.style.dialog, "", new CommomDialog.OnCloseListener() {
            @Override
            public void onClick(Dialog dialog, boolean confirm) {
                if (confirm) {
                    Toast.makeText(MainActivity.this,"被删除了,调用删除接口",Toast.LENGTH_SHORT).show();
                    dialog.dismiss();
                }

            }
        }).setTitle("你确定要删除吗?").show();
    }
}

adpter 的代码

package view.dome.com.shoppingcartdome.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.bumptech.glide.Glide;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

import view.dome.com.shoppingcartdome.R;
import view.dome.com.shoppingcartdome.bean.ShoppingBean;
import view.dome.com.shoppingcartdome.bean.UpdataButton;
import view.dome.com.shoppingcartdome.utils.StringUtils;

/**
 * Created by Administrator on 2018/4/9 0009.
 */

public class ShoppingcaCartAdapter extends RecyclerView.Adapter {
    private Context mContext;
    private View headerView;
    private List mDatas;
    private OnEditClickListener mOnEditClickListener;

    private OnDeleteClickListener mOnDeleteClickListener;

    private LayoutInflater inflater;
    private OnRecyclerViewItemClickListener onItemClickListener;
    ShoppingBean.DataBean bean;
    ShoppingCartAdapter shoppingCartAdapter;

    public ShoppingcaCartAdapter(Context context, List jsonArray, ShoppingBean.DataBean bean, ShoppingCartAdapter mallShopCartAdapter2) {
        this.mContext = context;
        this.mDatas = jsonArray;
        this.bean = bean;
        this.shoppingCartAdapter = mallShopCartAdapter2;
        inflater = LayoutInflater.from(mContext);
    }

    @Override
    public ShoppingcaCartAdapter.MyShoppViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view;
        view = LayoutInflater.from(mContext).inflate(R.layout.item_shopcartview, parent, false);
        return new ShoppingcaCartAdapter.MyShoppViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final ShoppingcaCartAdapter.MyShoppViewHolder holder, final int position) {
        String goods_name = mDatas.get(position).getGoods_name(); //商品名称
        String goods_image = mDatas.get(position).getGoods_image();  //图片
        int goods_num = mDatas.get(position).getGoods_num(); //数量
        double goods_price = mDatas.get(position).getGoods_price();  //商品价格
        String goods_points = mDatas.get(position).getGoods_points();//积分


        if (!StringUtils.isEmpty(goods_name)) {
            holder.tvShopCartClothName.setText(goods_name);
        }

        if (!StringUtils.isEmpty(goods_image)) {
            Glide.with(mContext).load(goods_image).error(R.mipmap.log_img) .into(holder.ivShopCartClothPic);
        }

        if (!StringUtils.isEmpty(goods_num + "")) {
            holder.etShopCartClothNum.setText(goods_num + "");
        }

        holder.tvShopCartClothPrice.setText(goods_price + "");
        if (!StringUtils.isEmpty(goods_points)) {
            holder.GoodsPoints.setText(goods_points + "积分");
        }


        /**
         *  点击减号
         */
        holder.ivShopCartClothMinus.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mDatas.get(position).getGoods_num() > 1) {
                    int count = mDatas.get(position).getGoods_num() - 1;
                    if (mOnEditClickListener != null) {
                        mOnEditClickListener.onEditClick(position, mDatas.get(position).getUser_id(), count);
                    }
                    mDatas.get(position).setGoods_num(count);
                    EventBus.getDefault().post(new UpdataButton(shoppingCartAdapter.getAllPrice()));
                    notifyDataSetChanged();
                }
            }
        });

        /**
         * 加号的点击
         */
        holder.ivShopCartClothAdd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int count = mDatas.get(position).getGoods_num() + 1;
                if (mOnEditClickListener != null) {
                    mOnEditClickListener.onEditClick(position, mDatas.get(position).getUser_id(), count);
                }
                mDatas.get(position).setGoods_num(count);
                EventBus.getDefault().post(new UpdataButton(shoppingCartAdapter.getAllPrice()));
                notifyDataSetChanged();
            }
        });
        /**
         * 商品删除
         */
        holder.ivShopCartClothDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                showDialog(v, position);
            }
        });

        holder.ivShopCartClothSel.setOnCheckedChangeListener(null);

        final ShoppingBean.DataBean.ListBean cartBean = mDatas.get(position);
        //读取实体内存储的选中状态
        holder.ivShopCartClothSel.setChecked(cartBean.isSelect());

        holder.ivShopCartClothSel.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                //更改item选中状态同时进行实体内的选中状态改变
                cartBean.setSelect(isChecked);
                boolean noSelect = false;
                //内层item选中状态改变后要遍历判断是否全选,以改变外层item的选中状态
                for (ShoppingBean.DataBean.ListBean cartItemResultDtoList : mDatas) {
                    if (!cartItemResultDtoList.isSelect()) {
                        noSelect = true;
                    }
                }
                if (!noSelect) {
                    bean.setSelect(!noSelect);
                    shoppingCartAdapter.notifyDataSetChanged();
                } else {
                    bean.setSelect(!noSelect);
                    shoppingCartAdapter.notifyDataSetChanged();
                }
                EventBus.getDefault().post(new UpdataButton(shoppingCartAdapter.getAllPrice()));
            }
        });

        holder.itemView.setTag(mDatas.get(position));//传object回去

        holder.parenttView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });


    }

    private void showDialog(final View view, final int position) {
        //调用删除某个规格商品的接口
        if (mOnDeleteClickListener != null) {
            mOnDeleteClickListener.onDeleteClick(view, position, mDatas.get(position).getGoods_id());
        }
        mDatas.remove(position);
        notifyDataSetChanged();
    }


    @Override
    public int getItemCount() {
        return (mDatas == null ? 0 : mDatas.size());
    }

    class MyShoppViewHolder extends RecyclerView.ViewHolder {

        private TextView tvShopCartClothName;
        private TextView tvShopCartClothPrice;
        private TextView etShopCartClothNum;
        private CheckBox ivShopCartClothSel;
        private TextView ivShopCartClothMinus;
        private TextView ivShopCartClothAdd;
        private ImageView ivShopCartClothDelete;
        private ImageView ivShopCartClothPic;
        private TextView GoodsPoints;
        private LinearLayout parenttView;

        public MyShoppViewHolder(View view) {
            super(view);
            tvShopCartClothName = (TextView) view.findViewById(R.id.tv_item_shopcart_clothname); //商品名称
            tvShopCartClothPrice = (TextView) view.findViewById(R.id.tv_shopping_rmb); //价格
            etShopCartClothNum = (TextView) view.findViewById(R.id.et_item_shopcart_cloth_num); //商品数量
            ivShopCartClothSel = (CheckBox) view.findViewById(R.id.tv_item_shopcart_clothselect); //商品是否选中
            ivShopCartClothMinus = (TextView) view.findViewById(R.id.iv_item_shopcart_cloth_minus); //减号
            ivShopCartClothAdd = (TextView) view.findViewById(R.id.iv_item_shopcart_cloth_add); //加号
            ivShopCartClothPic = (ImageView) view.findViewById(R.id.iv_item_shopcart_cloth_pic); //图片
            ivShopCartClothDelete = (ImageView) view.findViewById(R.id.iv_item_shopcart_cloth_delete);//商品删除
            GoodsPoints = (TextView) view.findViewById(R.id.tv_goods_points);
            parenttView = (LinearLayout) view.findViewById(R.id.ll_parenttView);
        }
    }

    /**
     * 减的监听
     */
    public interface OnEditClickListener {
        void onEditClick(int position, String cartid, int count);
    }


    /**
     * 删除按键
     */
    public interface OnDeleteClickListener {
        void onDeleteClick(View view, int position, String cartid);
    }

    public interface OnRecyclerViewItemClickListener {
        void onItemClick(View view, ShoppingBean.DataBean.ListBean data);
    }

    public void setOnItemClickListener(OnRecyclerViewItemClickListener listener) {
        this.onItemClickListener = listener;
    }

    public void setAllselect(boolean b) {
        for (int i = 0; i < mDatas.size(); i++) {
            mDatas.get(i).setSelect(b);
        }
    }
}

子类的适配器

package view.dome.com.shoppingcartdome.adapter;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import org.greenrobot.eventbus.EventBus;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import view.dome.com.shoppingcartdome.MainActivity;
import view.dome.com.shoppingcartdome.R;
import view.dome.com.shoppingcartdome.bean.ShoppingBean;
import view.dome.com.shoppingcartdome.bean.UpdataButton;
import view.dome.com.shoppingcartdome.utils.Arith;
import view.dome.com.shoppingcartdome.utils.StringUtils;
import view.dome.com.shoppingcartdome.utils.ToastUtils;


/**
 * Created by Administrator on 2018/4/9 0009.
 *   购物车的适配器
 */

public class ShoppingCartAdapter extends RecyclerView.Adapter implements View.OnClickListener {
    private Context context;
    private List data;
    public ShoppingcaCartAdapter mShopCartAdapter;
    private OnRecyclerViewItemClickListener  onItemClickListener;
    private  OndeleteidClickListener ondeleteidClickListener;
    private List mList;

    public ShoppingCartAdapter(Context context, List data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public ShoppingCartAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(context).inflate(R.layout.item_shopcart, parent, false);
        MyViewHolder holder= new MyViewHolder(view);
        view.setOnClickListener(this);
        return holder;
    }

    @Override
    public void onBindViewHolder(final ShoppingCartAdapter.MyViewHolder holder, final int position) {
        final ShoppingBean.DataBean cartBean = data.get(position);
        String Store_name = data.get(position).getStore_name();
        if (!StringUtils.isEmpty(Store_name)) {
            holder.tvShopCartShopName.setText(Store_name);     //商店名称
        }

        //删除
        holder.tvShopCartdefault.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String deleteID = getDeleteID(cartBean);
                if (ondeleteidClickListener!=null){
                    if (mList.size()==0){

                        Toast.makeText(context,"请选择需要删除的商品",Toast.LENGTH_SHORT).show();
                        return;
                    }
                    ondeleteidClickListener.onIdClick(v,deleteID);
                }
            }
        });

        holder.ivShopCartShopSel.setOnCheckedChangeListener(null);
        //读取实体内存储的选中状态
        holder.ivShopCartShopSel.setChecked(cartBean.isSelect());
        holder.ivShopCartShopSel.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                //更改item选中状态同时进行实体内的选中状态改变
                cartBean.setSelect(isChecked);
                //外层选中状态改变后,要遍历改变子recyclerView内item的选中状态
                for (ShoppingBean.DataBean.ListBean cartItemResultDtoList : cartBean.getList()) {
                    cartItemResultDtoList.setSelect(isChecked);
                }
                notifyDataSetChanged();
              EventBus.getDefault().post(new UpdataButton(getAllPrice()));
            }
        });
        holder.itemView.setTag(cartBean);//传object回去
        //单个商家的商品列表不需要滑动,所以在这里禁止掉商品item的滑动事件
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        };
        List listBeanList = data.get(position).getList();
        //这里是初始化商品item的recyclerView,将外层实例传入子层以便刷新
        mShopCartAdapter = new ShoppingcaCartAdapter(context, cartBean.getList(), cartBean, this);
        holder.recyChariView.setLayoutManager(linearLayoutManager);

        holder.recyChariView.setAdapter(mShopCartAdapter);
        //下面两句是防止刷新商品的recyclerView导致商家recyclerView也发生滑动
        holder.recyChariView.setFocusableInTouchMode(false);
        holder.recyChariView.requestFocus();

    }

    @Override
    public int getItemCount() {
       return  (data == null ? 0 : data.size());
    }

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

    /**
     * 点击事件
     * @param v
     */
    @Override
    public void onClick(View v) {
        if (onItemClickListener != null) {
            //注意这里使用getTag方法获取数据
            onItemClickListener.onItemClick(v,(ShoppingBean.DataBean) v.getTag());
        }
    }


    //设置全选/全不选
    public void setAllselect(boolean b){
        for(int i=0;i mdata=data.get(i).getList();
                for (int y=0;y mDatas){
        this.data=mDatas;
    }
    public List getData(){

        return data;

    }

    //获取需要商品总价格
    public String getAllPrice(){
        BigDecimal allprice =new  BigDecimal("0");
        if(data!=null){
            for (int i=0;i mdata=data.get(i).getList();
                for (int y=0;y"+mdata.get(y).getGoods_price()); //价格
                        BigDecimal interestRate = new BigDecimal(mdata.get(y).getGoods_num()); //数量
                        double interest = Arith.mul(mdata.get(y).getGoods_price(), interestRate);
                        allprice=allprice.add(BigDecimal.valueOf(interest));
                        Log.i("总价", allprice+"allprice"+interest+"interestRate"+interestRate); //价格
                    }
                }
            }
        }
        return  allprice.toString();
    }

    //获取需要删除的商品id
    public String getDeleteProductID(){
        StringBuffer stringBuffer=new StringBuffer();
        if(data!=null){
            for (int i=0;i mdata=data.get(i).getList();
                for (int y=0;y();
        if (cartBean!=null){
            int size = cartBean.getList().size();
            mList.clear();
            for (int i = 0; i 

数据bean

package view.dome.com.shoppingcartdome.bean;

import java.io.Serializable;
import java.util.List;

/**
 * Created by guowei on 2018/3/8.
 */

public class ShoppingBean implements Serializable{


    /**
     * status : true
     * msg :
     * data : [{"store_name":"泊爱电脑手机","user_id":"2997","store_id":"15036517189924090000","list":[{"goods_price":2798,"cart_id":"15206697631223840000","member_id":"15167082162510250000","goods_id":"15157284674419540000","goods_num":"1","goods_name":"vivo X9s Plus 全网通 4GB+64GB","goods_image":"http://img.lion-mall.com/goods/20180112/f1ce79c40e7a16caef3d551e87cbd54f.jpg","spec_desc":"","spec1_name":"颜色","spec1_value":"黑 4+64全网通","spec2_name":"","spec2_value":"","proportion_return":"50","goods_points":0,"is_have_point":"1","model_id":"15157284674402800000"},{"goods_price":1499,"cart_id":"15206697301518310000","member_id":"15167082162510250000","goods_id":"15153949350638380000","goods_num":"5","goods_name":"华为手机NOVA 青春全网4-64G","goods_image":"http://img.lion-mall.com/goods/20180108/96ca747aeaffacc6b75be3f1b72827f0.png","spec_desc":"","spec1_name":"颜色","spec1_value":"蓝色","spec2_name":"","spec2_value":"","proportion_return":"50","goods_points":0,"is_have_point":"1","model_id":"15153949350627100000"},{"goods_price":11288,"cart_id":"15206693537135720000","member_id":"15167082162510250000","goods_id":"15157396518144480000","goods_num":"5","goods_name":" Apple MacBook Pro 13.3英寸笔记本电脑","goods_image":"http://img.lion-mall.com/goods/20180112/3c058df9cdb3c1e7ce786bbdc0186b39.jpg","spec_desc":"","spec1_name":"颜色","spec1_value":"银 新MACBOOK PRO-13寸I5-2.3/8-256GB","spec2_name":"","spec2_value":"","proportion_return":"50","goods_points":0,"is_have_point":"1","model_id":"15157396518138430000"}]},{"store_name":"芷兰堂 葩丽","user_id":"93","store_id":"14823227483019680000","list":[{"goods_price":32,"cart_id":"15206696136941370000","member_id":"15167082162510250000","goods_id":"15152137458906360000","goods_num":"1","goods_name":"葩丽 力度威高档内衣生物洗衣液","goods_image":"http://img.lion-mall.com/goods/20180106/a1895fe57a33502b676949cfbfbd2da1.jpg","spec_desc":"","spec1_name":"经典装","spec1_value":"1000ml(积分价)","spec2_name":"","spec2_value":"","proportion_return":"50","goods_points":13,"is_have_point":"1","model_id":"15152137458897290000"}]},{"store_name":"智能生活屋","user_id":"3090","store_id":"15110923292896270000","list":[{"goods_price":31.9,"cart_id":"15206693816469060000","member_id":"15167082162510250000","goods_id":"15172947866705000000","goods_num":"3","goods_name":"杜酷2.4g无线鼠标 办公鼠标 笔记本鼠标 MS302","goods_image":"http://img.lion-mall.com/goods/20180130/b160167b294c58ab46b7af21c14cc21e.jpg","spec_desc":"","spec1_name":"颜色","spec1_value":"宝石蓝(积分兑)","spec2_name":"","spec2_value":"","proportion_return":"50","goods_points":8,"is_have_point":"1","model_id":"15172947866684640000"},{"goods_price":98,"cart_id":"15206693711146970000","member_id":"15167082162510250000","goods_id":"15154810744773360000","goods_num":"12","goods_name":"杜酷(DUKU) 无线蓝牙键盘多屏双通道蓝牙键盘通用","goods_image":"http://img.lion-mall.com/goods/20180109/8885a44d743b75ccb0f3601686ddb719.jpg","spec_desc":"","spec1_name":"颜色","spec1_value":"黑色(积分价)","spec2_name":"","spec2_value":"","proportion_return":"50","goods_points":31,"is_have_point":"1","model_id":"15154810744751190000"}]},{"store_name":"缘礼贸易","user_id":"1124","store_id":"14880295292959680000","list":[{"goods_price":136,"cart_id":"15206693401010410000","member_id":"15167082162510250000","goods_id":"15166069210426020000","goods_num":"15","goods_name":"联创DF-EP2019M尊致电热水壶2L","goods_image":"http://img.lion-mall.com/goods/20180122/59db553319485bd32b067742aff4d3c2.png","spec_desc":"","spec1_name":"颜色","spec1_value":"图片色(积分兑)","spec2_name":"","spec2_value":"","proportion_return":"50","goods_points":89,"is_have_point":"1","model_id":"15166069210414950000"}]},{"store_name":"微超优品","user_id":"229","store_id":"14828331510902860000","list":[{"goods_price":63,"cart_id":"15206693220350690000","member_id":"15167082162510250000","goods_id":"15162477971822670000","goods_num":"8","goods_name":"飞科剃须刀FS829电动刮胡刀双刀头旋转式胡须刀","goods_image":"http://img.lion-mall.com/goods/20180118/52d39fb875525387d0eddce11e843fb3.jpg","spec_desc":"","spec1_name":"型号","spec1_value":"FS829(积分价)","spec2_name":"","spec2_value":"","proportion_return":"50","goods_points":16,"is_have_point":"1","model_id":"15162477971812280000"},{"goods_price":5165,"cart_id":"15206693117309630000","member_id":"15167082162510250000","goods_id":"15158120087923360000","goods_num":"5","goods_name":"创维55G7(55英寸)HDR4K超高清25核WIFI智能","goods_image":"http://img.lion-mall.com/goods/20180113/930e8be3bca4dce663427881c4a0bb64.jpg","spec_desc":"","spec1_name":"尺寸","spec1_value":"55英寸(积分价)","spec2_name":"","spec2_value":"","proportion_return":"50","goods_points":834,"is_have_point":"1","model_id":"15158120087913590000"}]}]
     */

    private boolean status;
    private String msg;
    private List data;

    public boolean isStatus() {
        return status;
    }

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

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public List getData() {
        return data;
    }

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

    public static class DataBean implements Serializable {
        /**
         * store_name : 泊爱电脑手机
         * user_id : 2997
         * store_id : 15036517189924090000
         * list : [{"goods_price":2798,"cart_id":"15206697631223840000","member_id":"15167082162510250000","goods_id":"15157284674419540000","goods_num":"1","goods_name":"vivo X9s Plus 全网通 4GB+64GB","goods_image":"http://img.lion-mall.com/goods/20180112/f1ce79c40e7a16caef3d551e87cbd54f.jpg","spec_desc":"","spec1_name":"颜色","spec1_value":"黑 4+64全网通","spec2_name":"","spec2_value":"","proportion_return":"50","goods_points":0,"is_have_point":"1","model_id":"15157284674402800000"},{"goods_price":1499,"cart_id":"15206697301518310000","member_id":"15167082162510250000","goods_id":"15153949350638380000","goods_num":"5","goods_name":"华为手机NOVA 青春全网4-64G","goods_image":"http://img.lion-mall.com/goods/20180108/96ca747aeaffacc6b75be3f1b72827f0.png","spec_desc":"","spec1_name":"颜色","spec1_value":"蓝色","spec2_name":"","spec2_value":"","proportion_return":"50","goods_points":0,"is_have_point":"1","model_id":"15153949350627100000"},{"goods_price":11288,"cart_id":"15206693537135720000","member_id":"15167082162510250000","goods_id":"15157396518144480000","goods_num":"5","goods_name":" Apple MacBook Pro 13.3英寸笔记本电脑","goods_image":"http://img.lion-mall.com/goods/20180112/3c058df9cdb3c1e7ce786bbdc0186b39.jpg","spec_desc":"","spec1_name":"颜色","spec1_value":"银 新MACBOOK PRO-13寸I5-2.3/8-256GB","spec2_name":"","spec2_value":"","proportion_return":"50","goods_points":0,"is_have_point":"1","model_id":"15157396518138430000"}]
         */

        private String store_name;
        private String user_id;
        private String store_id;
        private List list;
        private boolean data_tag;
        private  boolean isSelect;

        public boolean isData_tag() {
            return data_tag;
        }

        public boolean isSelect() {
            return isSelect;
        }

        public void setSelect(boolean select) {
            isSelect = select;
        }

        public void setData_tag(boolean data_tag) {
            this.data_tag = data_tag;
        }

        public boolean getData_tag() {
            return data_tag;
        }

        public String getStore_name() {
            return store_name;
        }

        public void setStore_name(String store_name) {
            this.store_name = store_name;
        }

        public String getUser_id() {
            return user_id;
        }

        public void setUser_id(String user_id) {
            this.user_id = user_id;
        }

        public String getStore_id() {
            return store_id;
        }

        public void setStore_id(String store_id) {
            this.store_id = store_id;
        }

        public List getList() {
            return list;
        }

        public void setList(List list) {
            this.list = list;
        }

        public static class ListBean implements Serializable{
            /**
             * goods_price : 2798
             * cart_id : 15206697631223840000
             * member_id : 15167082162510250000
             * goods_id : 15157284674419540000
             * goods_num : 1
             * goods_name : vivo X9s Plus 全网通 4GB+64GB
             * goods_image : http://img.lion-mall.com/goods/20180112/f1ce79c40e7a16caef3d551e87cbd54f.jpg
             * spec_desc :
             * spec1_name : 颜色
             * spec1_value : 黑 4+64全网通
             * spec2_name :
             * spec2_value :
             * proportion_return : 50
             * goods_points : 0
             * is_have_point : 1
             * model_id : 15157284674402800000
             */

            private double goods_price;
            private String cart_id;
            private String member_id;
            private String goods_id;
            private int goods_num;
            private String goods_name;
            private String goods_image;
            private String spec_desc;
            private String spec1_name;
            private String spec1_value;
            private String spec2_name;
            private String spec2_value;
            private String proportion_return;
            private String goods_points;
            private String is_have_point;
            private String model_id;
            private boolean isSelect;
            private  String user_id;

            public void setUser_id(String user_id) {
                this.user_id = user_id;
            }

            public String getUser_id() {
                return user_id;
            }

            public boolean isSelect() {
                return isSelect;
            }

            public void setSelect(boolean select) {
                isSelect = select;
            }

            private boolean goods_tag;

            public void setGoods_tag(boolean goods_tag) {
                this.goods_tag = goods_tag;
            }

            public boolean getGoods_tag() {
                return goods_tag;
            }

            public double getGoods_price() {
                return goods_price;
            }

            public void setGoods_price(double goods_price) {
                this.goods_price = goods_price;
            }

            public String getCart_id() {
                return cart_id;
            }

            public void setCart_id(String cart_id) {
                this.cart_id = cart_id;
            }

            public String getMember_id() {
                return member_id;
            }

            public void setMember_id(String member_id) {
                this.member_id = member_id;
            }

            public String getGoods_id() {
                return goods_id;
            }

            public void setGoods_id(String goods_id) {
                this.goods_id = goods_id;
            }

            public int getGoods_num() {
                return goods_num;
            }

            public void setGoods_num(int goods_num) {
                this.goods_num = goods_num;
            }

            public String getGoods_name() {
                return goods_name;
            }

            public void setGoods_name(String goods_name) {
                this.goods_name = goods_name;
            }

            public String getGoods_image() {
                return goods_image;
            }

            public void setGoods_image(String goods_image) {
                this.goods_image = goods_image;
            }

            public String getSpec_desc() {
                return spec_desc;
            }

            public void setSpec_desc(String spec_desc) {
                this.spec_desc = spec_desc;
            }

            public String getSpec1_name() {
                return spec1_name;
            }

            public void setSpec1_name(String spec1_name) {
                this.spec1_name = spec1_name;
            }

            public String getSpec1_value() {
                return spec1_value;
            }

            public void setSpec1_value(String spec1_value) {
                this.spec1_value = spec1_value;
            }

            public String getSpec2_name() {
                return spec2_name;
            }

            public void setSpec2_name(String spec2_name) {
                this.spec2_name = spec2_name;
            }

            public String getSpec2_value() {
                return spec2_value;
            }

            public void setSpec2_value(String spec2_value) {
                this.spec2_value = spec2_value;
            }

            public String getProportion_return() {
                return proportion_return;
            }

            public void setProportion_return(String proportion_return) {
                this.proportion_return = proportion_return;
            }

            public String getGoods_points() {
                return goods_points;
            }

            public void setGoods_points(String goods_points) {
                this.goods_points = goods_points;
            }

            public String getIs_have_point() {
                return is_have_point;
            }

            public void setIs_have_point(String is_have_point) {
                this.is_have_point = is_have_point;
            }

            public String getModel_id() {
                return model_id;
            }

            public void setModel_id(String model_id) {
                this.model_id = model_id;
            }
        }
    }
}

event类


public class UpdataButton {

    private String discribe;

    public UpdataButton(String discribe) {
        this.discribe = discribe;
    }

    public String getDiscribe() {
        return discribe;
    }

    public void setDiscribe(String discribe) {
        this.discribe = discribe;
    }
}

build.gradle

   //下拉刷新
    compile 'com.scwang.smartrefresh:SmartRefreshLayout:1.0.3'
    //没有使用特殊Header,可以不添加次依赖
    compile 'com.scwang.smartrefresh:SmartRefreshHeader:1.0.3'
    //eventbus
    compile 'org.greenrobot:eventbus:3.1.1'
    //recyclerview
    compile 'com.android.support:recyclerview-v7:26.1.0'
    //glide
    compile 'com.github.bumptech.glide:glide:3.7.0'
    //gson
    compile 'com.google.code.gson:gson:2.8.2'

你可能感兴趣的:(RecyclerView嵌套RecyclerView来实现购物车页面)