购物车参考

main主布局  导入RecyclerView依赖
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:id="@+id/rl_shopcart_have"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

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

            <android.support.v7.widget.RecyclerView
                android:id="@+id/recyclerView"
                android:layout_width="match_parent"
                android:layout_height="500dp">

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

        </LinearLayout>

        <LinearLayout
            android:id="@+id/ll_pay"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/white"
            android:gravity="center_vertical"
            android:orientation="horizontal"
            android:layout_alignParentBottom="true">

            <TextView
                android:id="@+id/allselect"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:drawableLeft="@drawable/shopcart_selected"
                android:drawablePadding="5dp"
                android:text="全选" />

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:orientation="vertical"
                android:layout_alignParentBottom="true">

                <TextView
                    android:id="@+id/tv_shopcart_totalprice"
                    android:layout_width="150dp"
                    android:layout_height="wrap_content"
                    android:paddingLeft="10dp"
                    android:paddingTop="10dp"
                    android:text="总价:¥0"
                    android:textColor="@android:color/holo_red_dark"
                    android:textSize="16sp" />

                <TextView
                    android:id="@+id/tv_Allnum"
                    android:layout_width="100dp"
                    android:layout_height="wrap_content"
                    android:paddingBottom="10dp"
                    android:paddingLeft="10dp"
                    android:text="共0件商品"
                    android:textSize="14sp" />

            </LinearLayout>

            <TextView
                android:id="@+id/jiesuan"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="10dp"
                android:background="@android:color/holo_red_light"
                android:paddingBottom="10dp"
                android:paddingLeft="30dp"
                android:paddingRight="30dp"
                android:paddingTop="10dp"
                android:text="去结算"
                android:textColor="@android:color/white"
                android:layout_alignParentBottom="true"/>

        </LinearLayout>

    </RelativeLayout>

</LinearLayout>
item条目  把图片放在drawable-xhdpi
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/white">

    <LinearLayout
        android:id="@+id/ll_shopcart_header"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        >
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_vertical"
            >

            <ImageView
                android:id="@+id/img_select"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/shopcart_selected"
                android:paddingLeft="15dp"
                android:paddingRight="15dp"
                android:paddingTop="10dp"
                android:paddingBottom="10dp"
                />

            <TextView
                android:id="@+id/tv_shopName"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:drawableLeft="@drawable/shopcart_shop"
                android:text="商家"
                android:padding="10dp"
                android:drawablePadding="5dp"
                />

        </LinearLayout>

    </LinearLayout>

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


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

            <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="#f6f6f6"
                ></View>

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

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/shopcart_selected"
                    android:layout_marginLeft="15dp"
                    android:layout_marginRight="15dp"
                    android:visibility="invisible"
                    />

                <TextView
                    android:id="@+id/tv_content"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="价格描述的内容"
                    android:paddingLeft="10dp"
                    android:paddingTop="10dp"
                    />
            </LinearLayout>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:gravity="center_vertical"
                >

                <ImageView
                    android:id="@+id/iv_smallSelect"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/shopcart_selected"
                    android:padding="15dp"
                    />

                <ImageView
                    android:id="@+id/iv_img"
                    android:layout_width="60dp"
                    android:layout_height="60dp"
                    android:layout_margin="10dp"
                    android:src="@mipmap/ic_launcher"
                    />

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

                    <TextView
                        android:id="@+id/tv_price"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="¥185"
                        android:layout_marginLeft="50dp"
                        android:textColor="#e53e42"
                        android:textSize="14sp"
                        android:layout_marginBottom="10dp"
                        />



                    <LinearLayout
                        android:layout_marginTop="5dp"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:gravity="center_vertical"
                        android:layout_marginLeft="50dp">

                        <ImageView
                            android:id="@+id/iv_jian"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:src="@drawable/shopcart_minus_grey"
                            />

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

                        <ImageView
                            android:id="@+id/iv_jia"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:src="@drawable/shopcart_add_red"
                            android:layout_marginLeft="5dp"
                            />

                    </LinearLayout>
                </LinearLayout>
                <Button
                    android:id="@+id/iv_delete"
                    android:layout_width="50dp"
                    android:layout_height="35dp"
                    android:padding="5dp"
                    android:text="删除"
                    android:textColor="@android:color/white"
                    android:background="@android:color/holo_red_light"
                    android:src="@drawable/shopcart_delete"
                    />

            </LinearLayout>
        </LinearLayout>

    </LinearLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#f6f6f6"
        ></View>
</LinearLayout>
  



Bean类ShopCartBean
导入List包
/**
     * shopId : 2
     * shopName : null
     * cartlist : [{"id":2,"shopId":2,"shopName":null,"productId":2,"productName":null,"color":null,"size":null,"price":null,"count":null}]
     */

    private int shopId;
    private Object shopName;
    /**
     * id : 2
     * shopId : 2
     * shopName : null
     * productId : 2
     * productName : null
     * color : null
     * size : null
     * price : null
     * count : null
     */

    private List<CartlistBean> cartlist;


    public int getShopId() {
        return shopId;
    }

    public void setShopId(int shopId) {
        this.shopId = shopId;
    }

    public Object getShopName() {
        return shopName;
    }

    public void setShopName(Object shopName) {
        this.shopName = shopName;
    }

    public List<CartlistBean> getCartlist() {
        return cartlist;
    }

    public void setCartlist(List<CartlistBean> cartlist) {
        this.cartlist = cartlist;
    }


    public static class CartlistBean {
        private int id;
        private int shopId;
        private String shopName;
        private int productId;
        private String productName;
        private String color;
        private String size;
        private String price;
        private String defaultPic;
        private int count;
        private boolean isSelect = true;
        private int isFirst = 2;
        private boolean isShopSelect = true;

        public String getDefaultPic() {
            return defaultPic;
        }

        public void setDefaultPic(String defaultPic) {
            this.defaultPic = defaultPic;
        }

        public boolean getIsShopSelect() {
            return isShopSelect;
        }

        public void setShopSelect(boolean shopSelect) {
            isShopSelect = shopSelect;
        }

        public int getIsFirst() {
            return isFirst;
        }

        public void setIsFirst(int isFirst) {
            this.isFirst = isFirst;
        }

        public boolean getIsSelect() {
            return isSelect;
        }

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

        public int getId() {
            return id;
        }

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

        public int getShopId() {
            return shopId;
        }

        public void setShopId(int shopId) {
            this.shopId = shopId;
        }

        public String getShopName() {
            return shopName;
        }

        public void setShopName(String shopName) {
            this.shopName = shopName;
        }

        public int getProductId() {
            return productId;
        }

        public void setProductId(int productId) {
            this.productId = productId;
        }

        public String getProductName() {
            return productName;
        }

        public void setProductName(String productName) {
            this.productName = productName;
        }

        public String getColor() {
            return color;
        }

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

        public String getSize() {
            return size;
        }

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

        public String getPrice() {
            return price;
        }

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

        public int getCount() {
            return count;
        }

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



创建适配器ShopCartAdapter
导包
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.bumptech.glide.Glide;
import java.util.List;

public class ShopCartAdapter extends RecyclerView.Adapter<ShopCartAdapter.MyViewHolder>{
    private Context context;
    private List<ShopCartBean.CartlistBean> data;
    private View headerView;
    private OnDeleteClickListener mOnDeleteClickListener;
    private OnEditClickListener mOnEditClickListener;
    private OnResfreshListener mOnResfreshListener;

    public ShopCartAdapter(Context context, List<ShopCartBean.CartlistBean> data){
        this.context = context;
        this.data = data;
    }

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



    @Override
    public void onBindViewHolder(final ShopCartAdapter.MyViewHolder holder, final int position) {

        Glide.with(context).load(data.get(position).getDefaultPic()).into(holder.img);
        if (position > 0) {
            if (data.get(position).getShopId() == data.get(position - 1).getShopId()) {
                holder.llShopCartHeader.setVisibility(View.GONE);
            } else {
                holder.llShopCartHeader.setVisibility(View.VISIBLE);
            }
        }else {
            holder.llShopCartHeader.setVisibility(View.VISIBLE);
        }
        holder.content.setText(data.get(position).getProductName());
        holder.shopName.setText(data.get(position).getShopName());
        holder.price.setText("¥" + data.get(position).getPrice());
        holder.num.setText(data.get(position).getCount() + "");

        if(mOnResfreshListener != null){
            boolean isSelect = false;
            for(int i = 0;i < data.size(); i++){
                if(!data.get(i).getIsSelect()){
                    isSelect = false;
                    break;
                }else{
                    isSelect = true;
                }
            }
            mOnResfreshListener.onResfresh(isSelect);
        }

        holder.jian.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(data.get(position).getCount() > 1) {
                    int count = data.get(position).getCount() - 1;
                    if (mOnEditClickListener != null) {
                        mOnEditClickListener.onEditClick(position, data.get(position).getId(), count);
                    }
                    data.get(position).setCount(count);
                    notifyDataSetChanged();
                }
            }
        });

        holder.jia.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int count = data.get(position).getCount() + 1;
                if(mOnEditClickListener != null){
                    mOnEditClickListener.onEditClick(position,data.get(position).getId(),count);
                }
                data.get(position).setCount(count);
                notifyDataSetChanged();
            }
        });

        //商家选中状态图片
        if(data.get(position).getIsSelect()){
            holder.smallSelect.setImageDrawable(context.getResources().getDrawable(R.drawable.shopcart_selected));
        }else {
            holder.smallSelect.setImageDrawable(context.getResources().getDrawable(R.drawable.shopcart_unselected));
        }

        //商品选中状态图片
        if(data.get(position).getIsShopSelect()){
            holder.select.setImageDrawable(context.getResources().getDrawable(R.drawable.shopcart_selected));
        }else {
            holder.select.setImageDrawable(context.getResources().getDrawable(R.drawable.shopcart_unselected));
        }

        holder.delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //调用删除的接口
                Delete(v,position);
            }
        });

        holder.smallSelect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                data.get(position).setSelect(!data.get(position).getIsSelect());
                //通过循环找出不同商铺的第一个商品的位置
                for(int i = 0;i < data.size(); i++){
                    if(data.get(i).getIsFirst() == 1) {
                        //遍历去找出同一家商铺的所有商品的勾选情况
                        for(int j = 0;j < data.size();j++){
                            //如果是同一家商铺的商品,并且其中一个商品是未选中,那么商铺的全选勾选取消
                            if(data.get(j).getShopId() == data.get(i).getShopId() && !data.get(j).getIsSelect()){
                                data.get(i).setShopSelect(false);
                                break;
                            }else{
                                //如果是同一家商铺的商品,并且所有商品是选中,那么商铺的选中全选勾选
                                data.get(i).setShopSelect(true);
                            }
                        }
                    }
                }
                notifyDataSetChanged();
            }
        });

        holder.select.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(data.get(position).getIsFirst() == 1) {
                    data.get(position).setShopSelect(!data.get(position).getIsShopSelect());
                    for(int i = 0;i < data.size();i++){
                        if(data.get(i).getShopId() == data.get(position).getShopId()){
                            data.get(i).setSelect(data.get(position).getIsShopSelect());
                        }
                    }
                    notifyDataSetChanged();
                }
            }
        });

    }

    private void Delete(final View view, final int position){
        //调用删除某个规格商品的接口
        if(mOnDeleteClickListener != null){
            mOnDeleteClickListener.onDeleteClick(view,position,data.get(position).getId());
        }
        data.remove(position);
        Toast.makeText(context, "删除成功", Toast.LENGTH_SHORT).show();
        //重新排序,标记所有商品不同商铺第一个的商品位置
        MainActivity.isSelectFirst(data);
        notifyDataSetChanged();
    }

    @Override
    public int getItemCount() {
        int count = (data == null ? 0 : data.size());
        if(headerView != null){
            count++;
        }
        return count;
    }


    class MyViewHolder extends RecyclerView.ViewHolder
    {
        private ImageView select;//CheckBox
        private TextView shopName;//商家名字
        private TextView content;//商品内容
        private TextView price;//商品价格
        private TextView num;//商品数量
        private ImageView smallSelect;//小CheckBox
        private ImageView jian;//减
        private ImageView jia;//加
        private Button delete;//删除
        private ImageView img;//商品图片
        private LinearLayout llShopCartHeader;

        public MyViewHolder(View view)
        {
            super(view);
            llShopCartHeader = (LinearLayout) view.findViewById(R.id.ll_shopcart_header);
            select = (ImageView) view.findViewById(R.id.img_select);
            shopName = (TextView) view.findViewById(R.id.tv_shopName);
            content = (TextView) view.findViewById(R.id.tv_content);
            price = (TextView) view.findViewById(R.id.tv_price);
            num = (TextView) view.findViewById(R.id.tv_num);
            smallSelect = (ImageView) view.findViewById(R.id.iv_smallSelect);
            jian = (ImageView) view.findViewById(R.id.iv_jian);
            jia = (ImageView) view.findViewById(R.id.iv_jia);
            img = (ImageView) view.findViewById(R.id.iv_img);
            delete = (Button) view.findViewById(R.id.iv_delete);
        }
    }


    public View getHeaderView(){
        return headerView;
    }

    private ShopCartAdapter.OnItemClickListener mOnItemClickListener;
    public interface OnItemClickListener{
        void onItemClick(View view, int position);
    }

    public void setOnItemClickListener(ShopCartAdapter.OnItemClickListener mOnItemClickListener){
        this.mOnItemClickListener = mOnItemClickListener;
    }

    public interface OnDeleteClickListener{
        void onDeleteClick(View view, int position, int cartid);
    }

    public void setOnDeleteClickListener(OnDeleteClickListener mOnDeleteClickListener){
        this.mOnDeleteClickListener = mOnDeleteClickListener;
    }

    public interface OnEditClickListener{
        void onEditClick(int position, int cartid, int count);
    }

    public void setOnEditClickListener(OnEditClickListener mOnEditClickListener){
        this.mOnEditClickListener = mOnEditClickListener;
    }

    public interface OnResfreshListener{
        void onResfresh(boolean isSelect);
    }

    public void setResfreshListener(OnResfreshListener mOnResfreshListener){
        this.mOnResfreshListener = mOnResfreshListener;
    }

}



MainActivity类
导包
import android.graphics.drawable.Drawable;
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.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import licancan.com.recyclerviewcar.adapter.ShopCartAdapter;
import licancan.com.recyclerviewcar.api.Api;
import licancan.com.recyclerviewcar.bean.ShopCartBean;
import licancan.com.recyclerviewcar.utils.OkHttpUtils;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class MainActivity extends AppCompatActivity {
    private TextView jiesuan,allselect,tv_Allnum;
    private RecyclerView recyclerView;
    private ShopCartAdapter adapter;
    private List<ShopCartBean.CartlistBean> mAllOrderList = new ArrayList<>();
    private ArrayList<ShopCartBean.CartlistBean> mGoPayList = new ArrayList<>();
    private List<String> mHotProductsList = new ArrayList<>();
    private TextView CarAllPrice;
    private int mCount,mPosition;
    private float allPrice;
    private boolean mSelect;

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

        //创建LinearLayoutManager管理器
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        //创建适配器  关联适配器
        adapter = new ShopCartAdapter(this,mAllOrderList);
        recyclerView.setAdapter(adapter);
        //删除商品接口
        adapter.setOnDeleteClickListener(new ShopCartAdapter.OnDeleteClickListener() {
            @Override
            public void onDeleteClick(View view, int position,int cartid) {
                adapter.notifyDataSetChanged();
            }
        });
        //修改数量接口
        adapter.setOnEditClickListener(new ShopCartAdapter.OnEditClickListener() {
            @Override
            public void onEditClick(int position, int cartid, int count) {
                mCount = count;
                mPosition = position;
            }
        });
        //判断全选按钮
        adapter.setResfreshListener(new ShopCartAdapter.OnResfreshListener() {
            @Override
            public void onResfresh( boolean isSelect) {
                mSelect = isSelect;
                if(isSelect){
                    Drawable left = getResources().getDrawable(R.drawable.shopcart_selected);
                    allselect.setCompoundDrawablesWithIntrinsicBounds(left,null,null,null);
                }else {
                    Drawable left = getResources().getDrawable(R.drawable.shopcart_unselected);
                    allselect.setCompoundDrawablesWithIntrinsicBounds(left,null,null,null);
                }
                float allPrice = 0;
                int allNum = 0;
                allPrice = 0;
                mGoPayList.clear();
                for(int i = 0;i < mAllOrderList.size(); i++)
                    if(mAllOrderList.get(i).getIsSelect()) {
                        allPrice += Float.parseFloat(mAllOrderList.get(i).getPrice()) * mAllOrderList.get(i).getCount();
                        allNum += 1;
                        mGoPayList.add(mAllOrderList.get(i));
                    }
                allPrice = allPrice;
                CarAllPrice.setText("总价:" + allPrice);
                tv_Allnum.setText("共" + allNum + "件商品");
                jiesuan.setText("结算"+"("+allNum+")");
            }
        });

        //全选
        allselect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mSelect = !mSelect;
                if(mSelect){
                    Drawable left = getResources().getDrawable(R.drawable.shopcart_selected);
                    allselect.setCompoundDrawablesWithIntrinsicBounds(left,null,null,null);
                    for(int i = 0;i < mAllOrderList.size();i++){
                        mAllOrderList.get(i).setSelect(true);
                        mAllOrderList.get(i).setShopSelect(true);
                    }
                }else{
                    Drawable left = getResources().getDrawable(R.drawable.shopcart_unselected);
                    allselect.setCompoundDrawablesWithIntrinsicBounds(left,null,null,null);
                    for(int i = 0;i < mAllOrderList.size();i++){
                        mAllOrderList.get(i).setSelect(false);
                        mAllOrderList.get(i).setShopSelect(false);
                    }
                }
                adapter.notifyDataSetChanged();
            }
        });
        adapter.notifyDataSetChanged();
    }

    /**
     * 初始化控件
     */
    private void initView() {
        allselect = (TextView) findViewById(R.id.allselect);
        CarAllPrice = (TextView) findViewById(R.id.tv_shopcart_totalprice);
        tv_Allnum = (TextView) findViewById(R.id.tv_Allnum);
        recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
        jiesuan = (TextView) findViewById(R.id.jiesuan);
    }

    private void initData() {
        OkHttpUtils.doGet(Api.URL, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String result = response.body().string();
            }
        });
    }
    private void initMyData(){
        for(int i = 0;i < 2;i ++){
            ShopCartBean.CartlistBean sb = new ShopCartBean.CartlistBean();
            sb.setShopId(1);
            sb.setPrice("5199.0");
            sb.setDefaultPic("https://m.360buyimg.com/n0/jfs/t6700/155/2098998076/156185/6cf95035/595dd5a5Nc3a7dab5.jpg!q70.jpg");
            sb.setProductName("Apple iPhone 8 Plus (A1864) 64GB 金色 移动联通电信4G手机");
            sb.setShopName("商家1");
            sb.setCount(1);
            mAllOrderList.add(sb);
        }

        for(int i = 0;i < 1;i ++){
            ShopCartBean.CartlistBean sb = new ShopCartBean.CartlistBean();
            sb.setShopId(2);
            sb.setPrice("272.0");
            sb.setDefaultPic("https://m.360buyimg.com/n0/jfs/t9004/210/1160833155/647627/ad6be059/59b4f4e1N9a2b1532.jpg");
            sb.setProductName("北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g");
            sb.setShopName("商家6");
            sb.setCount(1);
            mAllOrderList.add(sb);
        }

        for(int i = 0;i < 2;i ++){
            ShopCartBean.CartlistBean sb = new ShopCartBean.CartlistBean();
            sb.setShopId(3);
            sb.setPrice("2434.0");
            sb.setDefaultPic("https://m.360buyimg.com/n0/jfs/t9106/106/1785172479/537280/253bc0ab/59bf78a7N057e5ff7.jpg");
            sb.setProductName("小米(MI) 小米MIX2 手机 黑色 全网通 (6GB+64GB)【标配版】");
            sb.setShopName("商家8");
            sb.setCount(1);
            mAllOrderList.add(sb);
        }

        for(int i = 0;i < 1;i ++){
            ShopCartBean.CartlistBean sb = new ShopCartBean.CartlistBean();
            sb.setShopId(4);
            sb.setPrice("4362.0");
            sb.setDefaultPic("https://m.360buyimg.com/n0/jfs/t6130/97/1370670410/180682/1109582a/593276b1Nd81fe723.jpg");
            sb.setProductName("全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G");
            sb.setShopName("商家10");
            sb.setCount(1);
            mAllOrderList.add(sb);
        }

        /*OkHttpClient ok = new OkHttpClient.Builder().build();
        FormBody.Builder fb = new FormBody.Builder();
        fb.add("uid","148");
        FormBody build = fb.build();
        Request re = new Request.Builder().post(build).url("http://120.27.23.105/product/getCarts")
                .build();
        ok.newCall(re).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String string = response.body().string();
                System.out.println("string = " + string);
                try {

                    JSONObject json = new JSONObject(string);
                    JSONArray data = json.getJSONArray("data");

                    for (int i = 0; i <data.length() ; i++) {
                        ShopCartBean.CartlistBean sb = new ShopCartBean.CartlistBean();
                        JSONObject o = (JSONObject) data.get(i);
                        String name = o.optString("sellerName");
                        int sellerid = o.optInt("sellerid");
                        sb.setShopId(sellerid);
                        sb.setShopName(name);
                        JSONArray list = o.optJSONArray("list");
                        for (int j = 0; j <list.length() ; j++) {
                            JSONObject o1 = (JSONObject) list.get(j);
                            String images = o1.getString("images").split("\\|")[0];
                            String title = o1.optString("title");
                            String price = o1.optString("price");
                            sb.setDefaultPic(images);
                            sb.setProductName(title);
                            sb.setPrice(price);
                            System.out.println("title = +======" + title);
                            mAllOrderList.add(sb);
                        }

                    }

                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }
        });*/
        isSelectFirst(mAllOrderList);
    }

    public static void isSelectFirst(List<ShopCartBean.CartlistBean> list){
        if(list.size() > 0) {
            list.get(0).setIsFirst(1);
            for (int i = 1; i < list.size(); i++) {
                if (list.get(i).getShopId() == list.get(i - 1).getShopId()) {
                    list.get(i).setIsFirst(2);
                } else {
                    list.get(i).setIsFirst(1);
                }
            }
        }
    }
}




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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值