购物车--可编辑

购物车主界面布局
<?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:orientation="vertical">
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:background="#f70828">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="c"
        android:textSize="26sp"
        android:layout_centerVertical="true"
        android:layout_marginLeft="10dp"
        android:id="@+id/fan" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="购物车"
        android:layout_centerInParent="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="编辑"
        android:id="@+id/bj"
        android:layout_centerInParent="true"
        android:layout_alignParentRight="true"
        android:layout_marginRight="10dp" />
</RelativeLayout>

<ExpandableListView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/elv"
    android:layout_weight="2"></ExpandableListView>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="8">

    <CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="全选"
        android:id="@+id/check_all"
        android:layout_centerVertical="true" />

    <LinearLayout
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:orientation="horizontal"
        android:id="@+id/caozuo">

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/share"
            android:background="#ed1ad8"
            android:textColor="#ffffff"
            android:text="分享宝贝"
            android:layout_margin="5dp" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/file"
            android:background="#ed1ad8"
            android:textColor="#ffffff"
            android:text="移到收藏栏"
            android:layout_margin="5dp"


            />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/dele"
            android:background="#f40616"
            android:textColor="#ffffff"
            android:text="删除"
            android:layout_margin="5dp" />
    </LinearLayout>

    <RelativeLayout
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:id="@+id/jiesuan"
        android:layout_centerVertical="true">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/price_all"
            android:layout_marginLeft="100dp"
            android:text="价钱"
            android:layout_centerVertical="true"

            />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/js"
            android:text="结算"
            android:layout_margin="5dp"
            android:background="#f40820"
            android:textColor="#ffffff"
            android:layout_alignParentRight="true" />
    </RelativeLayout>

</RelativeLayout>
</LinearLayout>
 
一级列表布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<CheckBox
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/shop_name"
    android:layout_centerVertical="true" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/item_bj"
    android:text="编辑"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"
    android:layout_marginRight="20dp" />
</RelativeLayout>
二级列表布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<CheckBox
    android:id="@+id/sel"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical" />

<com.facebook.drawee.view.SimpleDraweeView
    android:id="@+id/img"
    android:layout_width="150dp"
    android:layout_height="150dp" />

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:id="@+id/show"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

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

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

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

            <TextView
                android:id="@+id/price"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="#edb519" />

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

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


        </LinearLayout>
    </LinearLayout>

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

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/end"
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:background="#bac2ec"
                android:gravity="center"
                android:text="-" />

            <TextView
                android:id="@+id/num01"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="111" />

            <TextView
                android:id="@+id/add"
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:background="#bac2ec"
                android:gravity="center"
                android:text="+" />
        </LinearLayout>


        <Button
            android:id="@+id/del"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_alignParentRight="true"
            android:background="#f70d24"
            android:text="删除"
            android:textColor="#ffffff" />
    </RelativeLayout>
</RelativeLayout>
</LinearLayout>
建立在Activity之上的Fragment--购物车逻辑
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ExpandableListView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import java.util.ArrayList;
import java.util.List;

import lihuaizhan.bwie.com.lihuaizhanproject.R;
import lihuaizhan.bwie.com.lihuaizhanproject.adapter.MyAdapter;
import lihuaizhan.bwie.com.lihuaizhanproject.bean.CartBean;
import lihuaizhan.bwie.com.lihuaizhanproject.eventbus.Datas;
import lihuaizhan.bwie.com.lihuaizhanproject.eventbus.MessageEvent;
import lihuaizhan.bwie.com.lihuaizhanproject.eventbus.PriceAndCountEvent;
import lihuaizhan.bwie.com.lihuaizhanproject.presenter.GetCardPresenter;
import lihuaizhan.bwie.com.lihuaizhanproject.view.ICartFragment;


/**
 * Created by Administrator on 2017/11/11.
 */

public class Fragment04 extends Fragment implements View.OnClickListener,ICartFragment {
    private GetCardPresenter presenter;
    private MyAdapter adapter;
    private View view;
    /**
     * c
     */
    private TextView mFan;
    /**
     * 编辑
     */
    private TextView mBj;
    private ExpandableListView mElv;
    /**
     * 全选
     */
    private CheckBox mCheckAll;
    /**
     * 分享宝贝
     */
    private Button mShare;
    /**
     * 移到收藏栏
     */
    private Button mFile;
    /**
     * 删除
     */
    private Button mDele;
    private LinearLayout mCaozuo;
    /**
     * 价钱
     */
    private TextView mPriceAll;
    /**
     * 结算
     */
    private Button mJs;
    private RelativeLayout mJiesuan;
    private   List<List<CartBean.DataBean.ListBean>> lists = new ArrayList<>();
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment04, container, false);
        EventBus.getDefault().register(this);
        initView(view);
        presenter = new GetCardPresenter(this);
        presenter.getCarts();
        mCaozuo.setVisibility(View.GONE);

        return view;
    }
    @Subscribe
    public void onDatas(Datas datas)
    {
//        presenter1.onData(datas);
//        presenter2.onData(datas);

    }
    private void initView(View view) {
        mFan = (TextView) view.findViewById(R.id.fan);
        mBj = (TextView) view.findViewById(R.id.bj);
        mBj.setOnClickListener(this);
        mElv = (ExpandableListView) view.findViewById(R.id.elv);
        mCheckAll = (CheckBox) view.findViewById(R.id.check_all);
        mShare = (Button) view.findViewById(R.id.share);
        mShare.setOnClickListener(this);
        mFile = (Button) view.findViewById(R.id.file);
        mFile.setOnClickListener(this);
        mDele = (Button) view.findViewById(R.id.dele);
        mDele.setOnClickListener(this);
        mCaozuo = (LinearLayout) view.findViewById(R.id.caozuo);
        mPriceAll = (TextView) view.findViewById(R.id.price_all);
        mJs = (Button) view.findViewById(R.id.js);
        mJs.setOnClickListener(this);
        mJiesuan = (RelativeLayout) view.findViewById(R.id.jiesuan);
        mCheckAll.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                adapter.changeAllListCbState(mCheckAll.isChecked());
            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            default:
                break;
            case R.id.bj:
                mCaozuo.setVisibility(View.VISIBLE);
                mJiesuan.setVisibility(View.GONE);
                break;
            case R.id.share:
                break;
            case R.id.file:
                break;
            case R.id.dele:
                break;
            case R.id.js:
                break;
        }
    }

    @Override
    public void onShow(CartBean cartBean) {
        Toast.makeText(getActivity().getApplicationContext(),cartBean.getCode(),Toast.LENGTH_SHORT).show();
        List<CartBean.DataBean> data = cartBean.getData();

        for (int i = 0; i < data.size(); i++) {
            data.get(i).setBj("编辑");
            data.get(i).setWc("完成");
            List<CartBean.DataBean.ListBean> list = data.get(i).getList();
            lists.add(list);
        }
        adapter = new MyAdapter(getActivity(), data, lists);
        mElv.setAdapter(adapter);
        for (int i=0; i<data.size(); i++)
        {
            mElv.expandGroup(i);
        }
    }

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

    @Subscribe
    public void onMessageEvent(PriceAndCountEvent event) {
        mPriceAll.setText("结算(" + event.getCount() + ")"+event.getPrice() + "");

    }
    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }
}
适配器
import android.content.Context;
import android.content.DialogInterface;
import android.net.Uri;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.facebook.drawee.view.SimpleDraweeView;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import lihuaizhan.bwie.com.lihuaizhanproject.R;
import lihuaizhan.bwie.com.lihuaizhanproject.bean.BaseBean;
import lihuaizhan.bwie.com.lihuaizhanproject.bean.CartBean;
import lihuaizhan.bwie.com.lihuaizhanproject.eventbus.Datas;
import lihuaizhan.bwie.com.lihuaizhanproject.eventbus.MessageEvent;
import lihuaizhan.bwie.com.lihuaizhanproject.eventbus.PriceAndCountEvent;
import lihuaizhan.bwie.com.lihuaizhanproject.network.RetrofitHelper;


/**
 * Created by Administrator on 2017/12/11.
 */

public class MyAdapter extends BaseExpandableListAdapter {
    private Context context;
    private List<CartBean.DataBean> groupList;
    private List<List<CartBean.DataBean.ListBean>> childList;
    private LayoutInflater inflater;

    private AlertDialog show;
    private Boolean i01 = false;

    //    private MainActivity mainActivity;
//   private OnListiner<String> onListiner;
    public MyAdapter(Context context, List<CartBean.DataBean> groupList, List<List<CartBean.DataBean.ListBean>> childList) {
        this.context = context;
        this.groupList = groupList;
        this.childList = childList;
        inflater = LayoutInflater.from(context);
        //this.mainActivity = mainActivity;
    }

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

    @Override
    public View getGroupView(final int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        final GroupViewHolder holder1;
        View view = null;
        if (convertView == null) {
            holder1 = new GroupViewHolder();
            view = inflater.inflate(R.layout.group_item, parent, false);
            holder1.shopName = view.findViewById(R.id.shop_name);
            holder1.itemBj = view.findViewById(R.id.item_bj);
            view.setTag(holder1);
        } else {
            view = convertView;
            holder1 = (GroupViewHolder) view.getTag();
        }
        final CartBean.DataBean dataBean = groupList.get(groupPosition);
        holder1.shopName.setText(dataBean.getSellerName());
        Boolean check = dataBean.getCheck();
        holder1.shopName.setChecked(dataBean.getCheck());
        holder1.itemBj.setText(dataBean.getBj());

        holder1.itemBj.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //  List<CartBean.DataBean.ListBean> listBeans = childList.get(groupPosition);
                List<CartBean.DataBean.ListBean> list = dataBean.getList();
                if (i01 == false) {
                    i01 = true;
                    dataBean.setBj("完成");
                    for (int i = 0; i < list.size(); i++) {
                        list.get(i).setShow(false);

                    }
                    notifyDataSetChanged();
                } else {
                    i01 = false;
                    dataBean.setBj("编辑");
                    for (int i = 0; i < list.size(); i++) {
                        list.get(i).setShow(true);

                    }
                    notifyDataSetChanged();
                }

                notifyDataSetChanged();
            }
        });
        holder1.shopName.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dataBean.setCheck(holder1.shopName.isChecked());
                changeChildCbState(groupPosition, holder1.shopName.isChecked());
                EventBus.getDefault().post(compute());
                changeAllCbState(isAllGroupCbSelected());
                notifyDataSetChanged();
            }
        });
        return view;
    }

    @Override
    public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
        final ChildViewHolder holder;
        View view = null;
        if (convertView == null) {
            holder = new ChildViewHolder();
            view = inflater.inflate(R.layout.child_item, parent, false);
            holder.dele = view.findViewById(R.id.del);
            holder.add = view.findViewById(R.id.add);
            holder.end = view.findViewById(R.id.end);
            holder.sel = view.findViewById(R.id.sel);
            holder.img = view.findViewById(R.id.img);
            holder.name = view.findViewById(R.id.name);
            holder.price = view.findViewById(R.id.price);
            holder.prices = view.findViewById(R.id.prices);
            holder.jieShao = view.findViewById(R.id.jie_shao);
            holder.num = view.findViewById(R.id.num);
            holder.show = view.findViewById(R.id.show);
            holder.hide = view.findViewById(R.id.hide);
            holder.num01 = view.findViewById(R.id.num01);
            view.setTag(holder);
        } else {
            view = convertView;
            holder = (ChildViewHolder) view.getTag();
        }
        final CartBean.DataBean.ListBean listBean = childList.get(groupPosition).get(childPosition);
        holder.hide.setVisibility(View.GONE);
        holder.jieShao.setText(listBean.getSubhead());
        holder.num.setText("数量:" + listBean.getNum());
        holder.num01.setText(listBean.getNum() + "");
        holder.price.setText("$" + listBean.getPrice());
        holder.prices.setText("$" + listBean.getBargainPrice());
//        if(listBean.getSelected()==0)
//        {  listBean.setCheck(true);
//
//
//        }
//        else {
//            listBean.setCheck(false);
//
//
//
//        }
        holder.sel.setChecked(listBean.getCheck());
        String images = listBean.getImages();
        String[] split = images.split("\\|");
        Uri parse = Uri.parse(split[0]);
        holder.img.setImageURI(parse);
        holder.name.setText(listBean.getTitle());
        int pid = listBean.getPid();
        final String pid01 = pid + "";
        final int selected = listBean.getSelected();
        final String sellerid = listBean.getSellerid() + "";
        final String num = listBean.getNum() + "";
        if (listBean.getShow() == false) {
            holder.hide.setVisibility(View.VISIBLE);
            holder.show.setVisibility(View.GONE);
        } else {
            holder.hide.setVisibility(View.GONE);
            holder.show.setVisibility(View.VISIBLE);
        }
        holder.sel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //设置该条目对象里的checked属性值
                listBean.setCheck(holder.sel.isChecked());
                PriceAndCountEvent priceAndCountEvent = compute();
                EventBus.getDefault().post(priceAndCountEvent);

                if (holder.sel.isChecked()) {
                    //当前checkbox是选中状态
                    if (isAllChildCbSelected(groupPosition)) {
                        changGroupCbState(groupPosition, true);
                        changeAllCbState(isAllGroupCbSelected());
                    }
                } else {
                    changGroupCbState(groupPosition, false);
                    changeAllCbState(isAllGroupCbSelected());
                }
                notifyDataSetChanged();
            }
        });
        //加号
        holder.add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int num1 = listBean.getNum();
                num1++;
                holder.num01.setText(num1 + "");
                holder.num.setText(num1 + "");
                listBean.setNum(num1);
                if (holder.sel.isChecked()) {
                    PriceAndCountEvent priceAndCountEvent = compute();
                    EventBus.getDefault().post(priceAndCountEvent);
                }
            }
        });
        //减号
        holder.end.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int num = listBean.getNum();
                if (num == 1) {
                    return;
                }
                holder.num01.setText(--num + "");
                holder.num.setText(num + "");
                listBean.setNum(num);
                if (holder.sel.isChecked()) {
                    PriceAndCountEvent priceAndCountEvent = compute();
                    EventBus.getDefault().post(priceAndCountEvent);
                }
            }
        });
        //删除
        holder.dele.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


                final AlertDialog.Builder normalDialog =
                        new AlertDialog.Builder(context);
                normalDialog.setIcon(R.drawable.selectheart);
                normalDialog.setTitle("确认要删除此商品吗");
                normalDialog.setPositiveButton("确定",
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                //...To-do
                                RetrofitHelper.getApi().deleteGoodCar("71", childList.get(groupPosition).get(childPosition).getPid() + "")
                                        .subscribeOn(Schedulers.io())
                                        .observeOn(AndroidSchedulers.mainThread())
                                        .subscribe(new Observer<BaseBean>() {
                                            @Override
                                            public void onSubscribe(Disposable d) {

                                            }

                                            @Override
                                            public void onNext(BaseBean baseBean) {
                                                if (baseBean.getCode().equals("0")) {
                                                    List<CartBean.DataBean.ListBean> datasBeen = childList.get(groupPosition);
                                                    CartBean.DataBean.ListBean remove = datasBeen.remove(childPosition);
                                                    if (datasBeen.size() == 0) {
                                                        childList.remove(groupPosition);
                                                        groupList.remove(groupPosition);
                                                    }
                                                    EventBus.getDefault().post(compute());
                                                    notifyDataSetChanged();
                                                } else {
                                                    Toast.makeText(context, "删除失败", Toast.LENGTH_SHORT).show();
                                                }
                                            }

                                            @Override
                                            public void onError(Throwable e) {

                                            }

                                            @Override
                                            public void onComplete() {

                                            }
                                        });

                            }
                        });
                normalDialog.setNegativeButton("关闭",
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                //...To-do
                                show.dismiss();
                            }
                        });
                // 显示
                show = normalDialog.show();

            }
        });
        notifyDataSetChanged();
//        holder.dele.setOnClickListener(new View.OnClickListener() {
//           @Override
//           public void onClick(View v) {
//               Datas datas = new Datas();
//               datas.setPid(pid01);
//               datas.setSelected(selected);
//               datas.setSellerid(sellerid);
//               datas.setNum(num);
//
//               EventBus.getDefault().post(datas);
//               if (childList.get(groupPosition).size() == 0) {
//                   childList.remove(groupPosition);
//                   groupList.remove(groupPosition);
//               }
//               notifyDataSetChanged();
//           }
//       });
//    holder.add.setOnClickListener(new View.OnClickListener() {
//        @Override
//        public void onClick(View v) {
//            Datas datas = new Datas();
//            datas.setPid(pid01);
//            datas.setSelected(selected);
//            datas.setSellerid(sellerid);
//            datas.setNum(num);
//            EventBus.getDefault().post(datas);
//        }
//    });
        return view;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }

    class GroupViewHolder {
        CheckBox shopName;
        TextView itemBj;

    }

    class ChildViewHolder {
        CheckBox sel;
        SimpleDraweeView img;
        TextView name;
        TextView jieShao;
        TextView price;
        TextView prices;
        TextView num;
        TextView num01;
        Button dele;
        TextView add;
        TextView end;
        LinearLayout show;
        RelativeLayout hide;


    }

    /**
     * 计算列表中,选中的钱和数量
     */
    private PriceAndCountEvent compute() {
        int count = 0;
        int price = 0;
        for (int i = 0; i < childList.size(); i++) {
            List<CartBean.DataBean.ListBean> listBeans = childList.get(i);
            for (int j = 0; j < listBeans.size(); j++) {
                CartBean.DataBean.ListBean listBean = listBeans.get(j);
                if (listBean.getCheck()) {
                    price += listBean.getNum() * listBean.getPrice();
                    count += listBean.getNum();
                }
            }
        }
        PriceAndCountEvent priceAndCountEvent = new PriceAndCountEvent();
        priceAndCountEvent.setCount(count);
        priceAndCountEvent.setPrice(price);
        return priceAndCountEvent;
    }

    /**
     * 设置全选、反选
     *
     * @param flag
     */
    public void changeAllListCbState(boolean flag) {
        for (int i = 0; i < groupList.size(); i++) {
            changGroupCbState(i, flag);
            changeChildCbState(i, flag);
        }
        EventBus.getDefault().post(compute());
        notifyDataSetChanged();
    }

    /**
     * 判断一级列表是否全部选中
     *
     * @return
     */
    private boolean isAllGroupCbSelected() {
        for (int i = 0; i < groupList.size(); i++) {
            CartBean.DataBean dataBean = groupList.get(i);
            if (!dataBean.getCheck()) {
                return false;
            }
        }
        return true;
    }

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

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

    /**
     * 改变一级列表checkbox状态
     *
     * @param groupPosition
     */
    private void changGroupCbState(int groupPosition, boolean flag) {
        CartBean.DataBean dataBean = groupList.get(groupPosition);
        dataBean.setCheck(flag);
    }

    /**
     * 改变二级列表checkbox状态
     *
     * @param groupPosition
     * @param flag
     */
    private void changeChildCbState(int groupPosition, boolean flag) {
        List<CartBean.DataBean.ListBean> listBeans = childList.get(groupPosition);
        for (int i = 0; i < listBeans.size(); i++) {
            CartBean.DataBean.ListBean listBean = listBeans.get(i);
            listBean.setCheck(flag);
        }
    }
}
bean类
public class CartBean {
    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 {
        private String sellerName;
        private String sellerid;
        private List<ListBean> list;
        private String bj="编辑01";
        public String getBj() {
            return bj;
        }

        public void setBj(String bj) {
            this.bj = bj;
        }
        public String getSellerName() {
            return sellerName;
        }

        public void setSellerName(String sellerName) {
            this.sellerName = sellerName;
        }

        public String getSellerid() {
            return sellerid;
        }

        public void setSellerid(String sellerid) {
            this.sellerid = sellerid;
        }

        public List<ListBean> getList() {
            return list;
        }

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

        public static class ListBean {
            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 isShow=true;

            public Boolean getShow() {
                return isShow;
            }

            public void setShow(Boolean show) {
                isShow = show;
            }

            public double getBargainPrice() {
                return bargainPrice;
            }

            public void setBargainPrice(double bargainPrice) {
                this.bargainPrice = bargainPrice;
            }

            public String getCreatetime() {
                return createtime;
            }

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

            public String getDetailUrl() {
                return detailUrl;
            }

            public void setDetailUrl(String detailUrl) {
                this.detailUrl = detailUrl;
            }

            public String getImages() {
                return images;
            }

            public void setImages(String images) {
                this.images = images;
            }

            public int getNum() {
                return num;
            }

            public void setNum(int num) {
                this.num = num;
            }

            public int getPid() {
                return pid;
            }

            public void setPid(int pid) {
                this.pid = pid;
            }

            public double getPrice() {
                return price;
            }

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

            public int getPscid() {
                return pscid;
            }

            public void setPscid(int pscid) {
                this.pscid = pscid;
            }

            public int getSelected() {
                return selected;
            }

            public void setSelected(int selected) {
                this.selected = selected;
            }

            public int getSellerid() {
                return sellerid;
            }

            public void setSellerid(int sellerid) {
                this.sellerid = sellerid;
            }

            public String getSubhead() {
                return subhead;
            }

            public void setSubhead(String subhead) {
                this.subhead = subhead;
            }

            public String getTitle() {
                return title;
            }

            public void setTitle(String title) {
                this.title = title;
            }
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
基于C++&OPENCV 的全景图像拼接 C++是一种广泛使用的编程语言,它是由Bjarne Stroustrup于1979年在新泽西州美利山贝尔实验室开始设计开发的。C++是C语言的扩展,旨在提供更强大的编程能力,包括面向对象编程和泛型编程的支持。C++支持数据封装、继承和多态等面向对象编程的特性和泛型编程的模板,以及丰富的标准库,提供了大量的数据结构和算法,极大地提高了开发效率。12 C++是一种静态类型的、编译式的、通用的、大小写敏感的编程语言,它综合了高级语言和低级语言的特点。C++的语法与C语言非常相似,但增加了许多面向对象编程的特性,如类、对象、封装、继承和多态等。这使得C++既保持了C语言的低级特性,如直接访问硬件的能力,又提供了高级语言的特性,如数据封装和代码重用。13 C++的应用领域非常广泛,包括但不限于教育、系统开发、游戏开发、嵌入式系统、工业和商业应用、科研和高性能计算等领域。在教育领域,C++因其结构化和面向对象的特性,常被选为计算机科学和工程专业的入门编程语言。在系统开发领域,C++因其高效性和灵活性,经常被作为开发语言。游戏开发领域中,C++由于其高效性和广泛应用,在开发高性能游戏和游戏引擎中扮演着重要角色。在嵌入式系统领域,C++的高效和灵活性使其成为理想选择。此外,C++还广泛应用于桌面应用、Web浏览器、操作系统、编译器、媒体应用程序、数据库引擎、医疗工程和机器人等领域。16 学习C++的关键是理解其核心概念和编程风格,而不是过于深入技术细节。C++支持多种编程风格,每种风格都能有效地保证运行时间效率和空间效率。因此,无论是初学者还是经验丰富的程序员,都可以通过C++来设计和实现新系统或维护旧系统。3

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值