Android——二级列表实现购物车

来源:互联网 发布:交行信用卡淘宝有积分 编辑:程序博客网 时间:2024/04/26 05:40

效果图:

添加依赖:

compile 'com.squareup.okhttp3:okhttp:3.9.0'compile 'com.google.code.gson:gson:2.8.2'compile 'com.github.bumptech.glide:glide:3.7.0'compile 'org.greenrobot:eventbus:3.1.1'

项目清单中添加权限:

<uses-permission android:name="android.permission.INTERNET"/>

MVP模式:


HttpUtils

package com.bwie.com.myapplication.httputils;import android.os.Handler;import android.text.TextUtils;import android.util.Log;import com.bwie.com.myapplication.callback.CallBack;import java.io.IOException;import java.util.Map;import okhttp3.Call;import okhttp3.Callback;import okhttp3.OkHttpClient;import okhttp3.Request;import okhttp3.Response;/** * Created by Wangrx on 2017/11/18. */public class HttpUtils {    private static final String TAG = "HttpUtils";    private static volatile HttpUtils instance;    private static Handler handler = new Handler();    private HttpUtils() {    }    public static HttpUtils getInstance() {        if (null == instance) {            synchronized (HttpUtils.class) {                if (instance == null) {                    instance = new HttpUtils();                }            }        }        return instance;    }    /**     * Get请求     *     * @param url     * @param map     * @param callBack     * @param cls     * @param tag     */    public void get(String url, Map<String, String> map, final CallBack callBack,                    final Class cls, final String tag) {        // http://www.baoidu.com/login?mobile=11111&password=11111&age=1&name=zw        // 1.http://www.baoidu.com/login                -------- key=value&key=value        // 2.http://www.baoidu.com/login?               --------- key=value&key=value        // 3.http://www.baoidu.com/login?mobile=11111   -----&key=value&key=value        if (TextUtils.isEmpty(url)) {            return;        }        StringBuffer sb = new StringBuffer();        sb.append(url);        // 如果包含?说明是2.3类型        if (url.contains("?")) {            // 如果包含?并且?是最后一位,对应是2类型            if (url.indexOf("?") == url.length() - 1) {            } else {                // 如果包含?并且?不是最后一位,对应是3类型                sb.append("&");            }        } else {            // 不包含?,对应的1类型            sb.append("?");        }        // 遍历map集合进行拼接,拼接的形式是 key=value&        for (Map.Entry<String, String> entry : map.entrySet()) {            sb.append(entry.getKey())                    .append("=")                    .append(entry.getValue())                    .append("&");        }        // 如果存在&号,把最后一个&去掉        if (sb.indexOf("&") != -1) {            sb.deleteCharAt(sb.lastIndexOf("&"));        }        Log.i(TAG, "get url: " + sb);        OkHttpClient client = new OkHttpClient();        final Request request = new Request.Builder()                .get()                .url(sb.toString())                .build();        Call call = client.newCall(request);        call.enqueue(new Callback() {            @Override            public void onFailure(Call call, final IOException e) {                handler.post(new Runnable() {                    @Override                    public void run() {                        // 通过自己传进来的回调接口对象回传回去                        callBack.onFailed(tag, e);                    }                });            }            @Override            public void onResponse(Call call, Response response) throws IOException {                final String result = response.body().string();                // 请求成功之后做解析,通过自己的回调接口将数据返回回去                handler.post(new Runnable() {                    @Override                    public void run() {                        Object o;                        if (TextUtils.isEmpty(result)) {                            o = null;                        } else {                            o = GsonUtils.getInstance().fromJson(result, cls);                        }                        callBack.onSuccess(tag, o);                    }                });            }        });    }}
GsonUtils

package com.bwie.com.myapplication.httputils;import com.google.gson.Gson;/** * Created by Wangrx on 2017/11/18. */public class GsonUtils {    private static Gson instance;        private GsonUtils(){        }        public static Gson getInstance(){            if (instance==null){                instance = new Gson();            }            return instance;        }}
CartPresenter

package com.bwie.com.myapplication.presenter;import android.util.Log;import com.bwie.com.myapplication.bean.CartBean;import com.bwie.com.myapplication.callback.CallBack;import com.bwie.com.myapplication.callback.CartCallBack;import com.bwie.com.myapplication.httputils.HttpUtils;import java.util.HashMap;import java.util.List;import java.util.Map;/** * Created by Wangrx on 2017/11/18. */public class CartPresenter {    private CartCallBack inv;    public void attachView(CartCallBack inv) {        this.inv = inv;    }    public void getNews() {        //type=top&key=dbedecbcd1899c9785b95cc2d17131c5        Map<String, String> map = new HashMap<>();//        map.put("cid", "1");//        map.put("key", "dbedecbcd1899c9785b95cc2d17131c5");        HttpUtils.getInstance().get("http://120.27.23.105/product/getCarts?uid=100", map, new CallBack() {            @Override            public void onSuccess(String tag, Object o) {                CartBean bean = (CartBean) o;                if (bean != null) {                    List<CartBean.DataBean> data = bean.getData();                    inv.success(tag, data);                    Log.i("zzzz", "onSuccess: "+ data.toString());                }            }            @Override            public void onFailed(String tag, Exception e) {                inv.failed(tag, e);            }        }, CartBean.class, "news");    }    public void detachView() {        if (inv != null) {            inv = null;        }    }}
CallBack

package com.bwie.com.myapplication.callback;/** * Created by Wangrx on 2017/11/18. */public interface CallBack {    void onSuccess(String tag, Object O);    void onFailed(String tag, Exception e);}
CartCallBack

package com.bwie.com.myapplication.callback;        import com.bwie.com.myapplication.bean.CartBean;        import java.util.List;/** * Created by Wangrx on 2017/11/18. */public interface CartCallBack {    void success(String tag, List<CartBean.DataBean> news);    void failed(String tag, Exception e);}
MessageEvent

package com.bwie.com.myapplication.eventbusevent;/** * Created by peng on 2017/11/17. */public class MessageEvent {    private boolean checked;    public boolean isChecked() {        return checked;    }    public void setChecked(boolean checked) {        this.checked = checked;    }}
PriceAndCountEvent

package com.bwie.com.myapplication.eventbusevent;/** * Created by peng on 2017/11/17. */public class PriceAndCountEvent {    private int price;    private int count;    public int getPrice() {        return price;    }    public void setPrice(int price) {        this.price = price;    }    public int getCount() {        return count;    }    public void setCount(int count) {        this.count = count;    }}
MyAdapter

package com.bwie.com.myapplication.adapter;import android.app.AlertDialog;import android.content.Context;import android.content.DialogInterface;import android.view.View;import android.view.ViewGroup;import android.widget.BaseExpandableListAdapter;import android.widget.CheckBox;import android.widget.ImageView;import android.widget.TextView;import com.bumptech.glide.Glide;import com.bwie.com.myapplication.R;import com.bwie.com.myapplication.bean.CartBean;import com.bwie.com.myapplication.eventbusevent.MessageEvent;import com.bwie.com.myapplication.eventbusevent.PriceAndCountEvent;import org.greenrobot.eventbus.EventBus;import java.util.List;/** * Created by Wangrx on 2017/11/22. */public class MyAdapter extends BaseExpandableListAdapter{    private Context context;    private List<CartBean.DataBean> groupList;    private List<List<CartBean.DataBean.ListBean>> childList;    public MyAdapter(Context context, List<CartBean.DataBean> groupList, List<List<CartBean.DataBean.ListBean>> childList) {        this.context =context;        this.groupList = groupList;        this.childList = childList;    }    @Override    public int getGroupCount() {        return groupList.size();    }    @Override    public int getChildrenCount(int i) {        return childList.get(i).size();    }    @Override    public Object getGroup(int i) {        return groupList.get(i);    }    @Override    public Object getChild(int i, int i1) {        return childList.get(i).get(i1);    }    @Override    public long getGroupId(int i) {        return i;    }    @Override    public long getChildId(int i, int i1) {        return i1;    }    @Override    public boolean hasStableIds() {        return false;    }    @Override    public View getGroupView(final int i, boolean b, View view, ViewGroup viewGroup) {        final GroupViewHolder holder;        if (view == null) {            holder = new GroupViewHolder();            view = view.inflate(context,R.layout.item_parent_market, null);            holder.cbGroup = view.findViewById(R.id.cb_parent);            holder.tv_number = view.findViewById(R.id.tv_number);            view.setTag(holder);        } else {            holder = (GroupViewHolder) view.getTag();        }        final CartBean.DataBean dataBean = groupList.get(i);        holder.cbGroup.setChecked(dataBean.isChecked());//        holder.tv_number.setText(dataBean.getTitle());        holder.tv_number.setText(dataBean.getSellerName());        //一级checkbox        holder.cbGroup.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                dataBean.setChecked(holder.cbGroup.isChecked());                changeChildCbState(i, holder.cbGroup.isChecked());                EventBus.getDefault().post(compute());                changeAllCbState(isAllGroupCbSelected());                notifyDataSetChanged();            }        });        return view;    }    @Override    public View getChildView(final int i, final int i1, boolean b, View view, ViewGroup viewGroup) {        final ChildViewHolder holder;        if (view == null) {            holder = new ChildViewHolder();            view = view.inflate(context,R.layout.item_child_market, null);            holder.cbChild = view.findViewById(R.id.cb_child);            holder.tv_tel = view.findViewById(R.id.tv_tel);//            holder.tv_content = view.findViewById(R.id.tv_content);//            holder.tv_time = view.findViewById(R.id.tv_time);            holder.imgIcon = view.findViewById(R.id.img_icon);            holder.tv_price = view.findViewById(R.id.tv_pri);            holder.tv_del = view.findViewById(R.id.tv_del);            holder.iv_add = view.findViewById(R.id.iv_add);            holder.iv_del = view.findViewById(R.id.iv_del);            holder.tv_num = view.findViewById(R.id.tv_num);            view.setTag(holder);        } else {            holder = (ChildViewHolder) view.getTag();        }        final CartBean.DataBean.ListBean datasBean = childList.get(i).get(i1);        holder.cbChild.setChecked(datasBean.isChecked());//        holder.tv_tel.setText(datasBean.getType_name());        holder.tv_tel.setText(datasBean.getTitle());//        holder.tv_content.setText(datasBean.getMsg());//        holder.tv_time.setText(datasBean.getAdd_time());        holder.tv_price.setText(""+datasBean.getPrice() );        holder.tv_num.setText(datasBean.getNum() + "");        String images = datasBean.getImages().trim();        String[] split = images.split("[|]");        Glide.with(context).load(split[0]).into(holder.imgIcon);        //二级checkbox        holder.cbChild.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                //设置该条目对象里的checked属性值                datasBean.setChecked(holder.cbChild.isChecked());                PriceAndCountEvent priceAndCountEvent = compute();                EventBus.getDefault().post(priceAndCountEvent);                if (holder.cbChild.isChecked()) {                    //当前checkbox是选中状态                    if (isAllChildCbSelected(i)) {                        changGroupCbState(i, true);                        changeAllCbState(isAllGroupCbSelected());                    }                } else {                    changGroupCbState(i, false);                    changeAllCbState(isAllGroupCbSelected());                }                notifyDataSetChanged();            }        });        //加号        holder.iv_add.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                int num = datasBean.getNum();                holder.tv_num.setText(++num + "");                datasBean.setNum(num);                if (holder.cbChild.isChecked()) {                    EventBus.getDefault().post(compute());                }            }        });        //减号        holder.iv_del.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                int num = datasBean.getNum();                if (num == 1) {                    return;                }                holder.tv_num.setText(--num + "");                datasBean.setNum(num);                if (holder.cbChild.isChecked()) {                    EventBus.getDefault().post(compute());                }            }        });        //删除        holder.tv_del.setOnClickListener(new View.OnClickListener() {            private AlertDialog dialog;            @Override            public void onClick(View v) {                final List<CartBean.DataBean.ListBean> datasBeen = childList.get(i);                AlertDialog.Builder builder = new AlertDialog.Builder(context);                builder.setTitle("提示");                builder.setMessage("确认是否删除?");                builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {                    @Override                    public void onClick(DialogInterface dialogInterface, int ii) {                        CartBean.DataBean.ListBean remove = datasBeen.remove(i1);                        if (datasBeen.size() == 0) {                            childList.remove(i);                            groupList.remove(i);                        }                        EventBus.getDefault().post(compute());                        notifyDataSetChanged();                    }                });                builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {                    @Override                    public void onClick(DialogInterface dialogInterface, int i) {                        dialog.dismiss();                    }                });                dialog = builder.create();                dialog.show();            }        });        return view;    }    @Override    public boolean isChildSelectable(int i, int i1) {        return false;    }    class GroupViewHolder {        CheckBox cbGroup;        TextView tv_number;    }    class ChildViewHolder {        CheckBox cbChild;        TextView tv_tel;        TextView tv_content;        TextView tv_time;        ImageView imgIcon;        TextView tv_price;        TextView tv_del;        ImageView iv_del;        ImageView iv_add;        TextView tv_num;    }    /**     * 改变全选的状态     *     * @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) {//        GoosBean.DataBean dataBean = groupList.get(groupPosition);        CartBean.DataBean dataBean = groupList.get(groupPosition);        dataBean.setChecked(flag);    }    /**     * 改变二级列表checkbox状态     *     * @param groupPosition     * @param flag     */    private void changeChildCbState(int groupPosition, boolean flag) {        List<CartBean.DataBean.ListBean> datasBeen = childList.get(groupPosition);        for (int i = 0; i < datasBeen.size(); i++) {            CartBean.DataBean.ListBean datasBean = datasBeen.get(i);            datasBean.setChecked(flag);        }    }    /**     * 判断一级列表是否全部选中     *     * @return     */    private boolean isAllGroupCbSelected() {        for (int i = 0; i < groupList.size(); i++) {            CartBean.DataBean dataBean = groupList.get(i);            if (!dataBean.isChecked()) {                return false;            }        }        return true;    }    /**     * 判断二级列表是否全部选中     *     * @param groupPosition     * @return     */    private boolean isAllChildCbSelected(int groupPosition) {        List<CartBean.DataBean.ListBean> datasBeen = childList.get(groupPosition);        for (int i = 0; i < datasBeen.size(); i++) {            CartBean.DataBean.ListBean datasBean = datasBeen.get(i);            if (!datasBean.isChecked()) {                return false;            }        }        return true;    }    /**     * 计算列表中,选中的钱和数量     */    private PriceAndCountEvent compute() {        int count = 0;        int price = 0;        for (int i = 0; i < childList.size(); i++) {            List<CartBean.DataBean.ListBean> datasBeen = childList.get(i);            for (int j = 0; j < datasBeen.size(); j++) {                CartBean.DataBean.ListBean datasBean = datasBeen.get(j);                if (datasBean.isChecked()) {                    price += datasBean.getNum() * datasBean.getPrice();                    count += datasBean.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();    }}
MainActivity

package com.bwie.com.myapplication;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.view.View;import android.widget.CheckBox;import android.widget.ExpandableListView;import android.widget.TextView;import com.bwie.com.myapplication.adapter.MyAdapter;import com.bwie.com.myapplication.bean.CartBean;import com.bwie.com.myapplication.callback.CartCallBack;import com.bwie.com.myapplication.eventbusevent.MessageEvent;import com.bwie.com.myapplication.eventbusevent.PriceAndCountEvent;import com.bwie.com.myapplication.presenter.CartPresenter;import org.greenrobot.eventbus.EventBus;import org.greenrobot.eventbus.Subscribe;import java.util.ArrayList;import java.util.List;public class MainActivity extends AppCompatActivity implements CartCallBack{    private List<CartBean.DataBean> groupList = new ArrayList<>();    private List<List<CartBean.DataBean.ListBean>> childList = new ArrayList<>();    private ExpandableListView mElv;    private CheckBox mCheckbox2;    /**     * 0     */    private TextView mTvPrice;    /**     * 结算(0)     */    private TextView mTvNum;    private MyAdapter adapter;    private CartPresenter presenter;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        initView();        adapter = new MyAdapter(this, groupList, childList);        mElv.setAdapter(adapter);        presenter = new CartPresenter();        presenter.attachView(this);        presenter.getNews();        mCheckbox2.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                adapter.changeAllListCbState(mCheckbox2.isChecked());            }        });    }    private void initView() {        mElv = (ExpandableListView) findViewById(R.id.elv);        mCheckbox2 = (CheckBox) findViewById(R.id.checkbox2);        mTvPrice = (TextView) findViewById(R.id.tv_price);        mTvNum = (TextView) findViewById(R.id.tv_num);    }    @Override    public void success(String tag, List<CartBean.DataBean> news) {        groupList.addAll(news);        for (int i = 0; i < news.size(); i++) {            List<CartBean.DataBean.ListBean> datas = news.get(i).getList();            childList.add(datas);        }        adapter.notifyDataSetChanged();        mElv.setGroupIndicator(null);        for (int i=0;i<groupList.size();i++){            mElv.expandGroup(i);        }    }    @Override    public void failed(String tag, Exception e) {    }    @Override    protected void onStart() {        super.onStart();        EventBus.getDefault().register(this);    }    @Subscribe    public void onMessageEvent(MessageEvent event) {        mCheckbox2.setChecked(event.isChecked());    }    @Subscribe    public void onMessageEvent(PriceAndCountEvent event) {        mTvNum.setText("结算(" + event.getCount() + ")");        mTvPrice.setText(""+event.getPrice() );    }    @Override    protected void onDestroy() {        super.onDestroy();        EventBus.getDefault().unregister(this);        if (presenter != null) {            presenter.detachView();        }    }}
布局文件:

activity_main.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout    xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    android:orientation="vertical"    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"    android:layout_height="match_parent" tools:context="com.bwie.com.myapplication.MainActivity">    <TextView        android:layout_width="match_parent"        android:layout_height="50dp"        android:gravity="center"        android:text="购物车"        android:textColor="#ff3660"        android:textSize="25sp" />    <ExpandableListView        android:id="@+id/elv"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:layout_weight="1" />    <RelativeLayout        android:layout_width="match_parent"        android:layout_height="50dp"        android:layout_alignParentBottom="true"        android:background="@android:color/white"        android:gravity="center_vertical">        <CheckBox            android:id="@+id/checkbox2"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_centerVertical="true"            android:layout_marginLeft="10dp"            android:button="@drawable/check_box_bg"            android:focusable="false" />        <TextView            android:layout_width="wrap_content"            android:layout_height="50dp"            android:layout_centerVertical="true"            android:layout_marginLeft="10dp"            android:layout_toRightOf="@+id/checkbox2"            android:gravity="center_vertical"            android:text="全选"            android:textSize="20sp" />        <LinearLayout            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_alignParentRight="true"            android:orientation="horizontal">            <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_marginLeft="10dp"                android:text="合计 :" />            <TextView                android:id="@+id/tv_price"                android:layout_width="wrap_content"                android:layout_height="50dp"                android:layout_marginLeft="10dp"                android:paddingRight="10dp"                android:text="0"                android:textColor="@android:color/holo_red_light" />            <TextView                android:id="@+id/tv_num"                android:layout_width="wrap_content"                android:layout_height="50dp"                android:background="@android:color/holo_red_dark"                android:gravity="center"                android:padding="10dp"                android:text="结算(0)"                android:textColor="@android:color/white" />        </LinearLayout>    </RelativeLayout></LinearLayout>
item_child_market.xml

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent">    <LinearLayout        android:layout_width="match_parent"        android:layout_height="match_parent"        android:layout_marginLeft="20dp"        android:orientation="horizontal"        android:gravity="center"        >        <CheckBox            android:id="@+id/cb_child"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:button="@drawable/check_box_bg"            android:focusable="false" />        <ImageView            android:id="@+id/img_icon"            android:layout_width="100dp"            android:layout_height="100dp"            android:src="@mipmap/ic_launcher" />        <LinearLayout            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_marginLeft="20dp"            android:orientation="vertical">            <TextView                android:id="@+id/tv_tel"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:textSize="20sp"                android:textStyle="bold"                android:singleLine="true"                android:text="iphone6" />            <TextView                android:id="@+id/tv_pri"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_marginTop="10dp"                android:textSize="18sp"                android:text="¥3000.00"                android:textColor="#f00" />            <LinearLayout                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_marginTop="10dp"                android:gravity="center_vertical">                <ImageView                    android:id="@+id/iv_del"                    android:layout_width="25dp"                    android:layout_height="25dp"                    android:src="@drawable/shopcart_minus_grey" />                <TextView                    android:id="@+id/tv_num"                    android:layout_width="wrap_content"                    android:layout_height="wrap_content"                    android:layout_marginLeft="5dp"                    android:background="@drawable/shopcart_add_btn"                    android:paddingBottom="2dp"                    android:paddingLeft="20dp"                    android:paddingRight="20dp"                    android:paddingTop="2dp"                    android:text="1"                    android:textSize="20sp"                    />                <ImageView                    android:id="@+id/iv_add"                    android:layout_width="25dp"                    android:layout_height="25dp"                    android:layout_marginLeft="5dp"                    android:src="@drawable/shopcart_add_red" />            </LinearLayout>        </LinearLayout>    </LinearLayout>    <TextView        android:id="@+id/tv_del"        android:layout_width="40dp"        android:layout_height="40dp"        android:background="@mipmap/deletes"        android:layout_alignParentRight="true"        android:layout_marginRight="10dp"        android:layout_marginTop="25dp"        android:layout_centerVertical="true"        android:gravity="center" /></RelativeLayout>
item_parent_market.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:gravity="center_vertical"    android:orientation="horizontal">    <RelativeLayout        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:background="@android:color/white" >        <CheckBox            android:id="@+id/cb_parent"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_centerVertical="true"            android:layout_marginLeft="10dp"            android:layout_marginRight="4dp"            android:button="@drawable/check_box_bg"            android:checkMark="?android:attr/listChoiceIndicatorMultiple"            android:gravity="center"            android:minHeight="38dp"            android:minWidth="32dp"            android:textAppearance="?android:attr/textAppearanceLarge"            android:visibility="visible" />        <TextView            android:id="@+id/tv_number"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_centerVertical="true"            android:layout_marginBottom="10dp"            android:layout_marginTop="10dp"            android:layout_toRightOf="@id/cb_parent"            android:background="@android:color/white"            android:drawableLeft="@drawable/shop_ico"            android:drawablePadding="10dp"            android:drawableRight="@drawable/s_jr_ico"            android:text="第八号当铺"            android:textColor="#666666"            android:textSize="18sp" />        <Button            android:id="@+id/tv_store_edtor"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_alignParentRight="true"            android:layout_centerVertical="true"            android:layout_marginRight="4dp"            android:background="@null"            android:text="编辑"            android:textSize="18sp"            />    </RelativeLayout></LinearLayout>
check_box_bg.xml

<?xml version="1.0" encoding="utf-8"?><selector  xmlns:android="http://schemas.android.com/apk/res/android">    <item android:drawable="@mipmap/ic_checked" android:state_checked="true"></item>    <item android:drawable="@mipmap/ic_uncheck"></item></selector>


改进版购物车

MainActivity

public class MainActivity extends AppCompatActivity implements IView {    private static final String TAG = "MainActivity";    @BindView(R.id.back)    ImageView back;    @BindView(R.id.title)    TextView title;    @BindView(R.id.subtitle)    TextView subtitle;    @BindView(R.id.top_bar)    LinearLayout topBar;    @BindView(R.id.exListView)    ExpandableListView exListView;    @BindView(R.id.all_chekbox)    CheckBox allChekbox;    @BindView(R.id.tv_total_price)    TextView tvTotalPrice;    @BindView(R.id.tv_go_to_pay)    TextView tvGoToPay;    @BindView(R.id.ll_info)    LinearLayout llInfo;    @BindView(R.id.tv_share)    TextView tvShare;    @BindView(R.id.tv_save)    TextView tvSave;    @BindView(R.id.tv_delete)    TextView tvDelete;    @BindView(R.id.ll_shar)    LinearLayout llShar;    @BindView(R.id.ll_cart)    LinearLayout llCart;    private int count = 0;    private List<SelCartBean.DataBean> list = new ArrayList<>();    private ShopCartExListAdapter adapter;    private boolean flag = false;    private int totalCount = 0;    private double totalPrice = 0.00;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        ButterKnife.bind(this);        getData();    }    @Override    protected void onStart() {        super.onStart();        EventBus.getDefault().register(this);    }    private void getData() {        ShopCartPresenter presenter = new ShopCartPresenter();        presenter.attachView(this);        Map<String, String> map = new HashMap<>();        map.put("uid", "101");        map.put("source", "android");        presenter.getCartListData(map);        adapter = new ShopCartExListAdapter(this, list);        exListView.setAdapter(adapter);    }    @Override    public void onSelCartSuccess(Object o) {        if (o instanceof List) {            List<SelCartBean.DataBean> dataBean = (List<SelCartBean.DataBean>) o;            list.addAll(dataBean);            adapter.notifyDataSetChanged();            for (int i = 0; i < adapter.getGroupCount(); i++) {                exListView.expandGroup(i);            }        }    }    @Override    public void onAddCartSuccess(Object o) {    }    @Override    public void onDelCartSuccess(Object o) {    }    @Override    public void onFailed(Exception e) {    }    public void delete() {        for (int i = 0; i < list.size(); i++) {            List<SelCartBean.DataBean.ListBean> listbean = list.get(i).getList();            for (int j = 0; j < listbean.size(); j++) {                SelCartBean.DataBean.ListBean listBean =listbean.get(j);                if (listBean.isChecked()) {                    listbean.remove(j);                    j--;                    if (listbean.size() == 0) {                        list.remove(i);                        i--;                    }                }            }        }        adapter.notifyDataSetChanged();    }    @OnClick({R.id.all_chekbox, R.id.tv_share, R.id.tv_save, R.id.tv_delete, R.id.subtitle,R.id.tv_go_to_pay})    public void onViewClicked(View view) {        switch (view.getId()) {            case R.id.all_chekbox:                adapter.changeAllListCbState(allChekbox.isChecked());                break;            case R.id.tv_share:                Toast.makeText(this, "分享成功", Toast.LENGTH_SHORT).show();                break;            case R.id.tv_save:                Toast.makeText(this, "加入成功", Toast.LENGTH_SHORT).show();                break;            case R.id.tv_delete:                AlertDialog dialog;                if (totalCount == 0) {                    Toast.makeText(MainActivity.this, "请选择要删除的商品", Toast.LENGTH_SHORT).show();                    return;                }                dialog = new AlertDialog.Builder(MainActivity.this).create();                dialog.setTitle("操作提示");                dialog.setMessage("您确定要将这些商品从购物车中移除吗?");                dialog.setButton(DialogInterface.BUTTON_NEGATIVE, "取消", new DialogInterface.OnClickListener() {                    @Override                    public void onClick(DialogInterface dialogInterface, int i) {                        return;                    }                });                dialog.setButton(DialogInterface.BUTTON_POSITIVE, "确定", new DialogInterface.OnClickListener() {                    @Override                    public void onClick(DialogInterface dialogInterface, int i) {                        delete();                    }                });                dialog.show();                break;            case R.id.subtitle:                flag = !flag;                if (flag) {                    subtitle.setText("完成");                    llShar.setVisibility(View.VISIBLE);                    llInfo.setVisibility(View.GONE);                } else {                    subtitle.setText("编辑");                    llShar.setVisibility(View.GONE);                    llInfo.setVisibility(View.VISIBLE);                }                break;            case R.id.tv_go_to_pay:                AlertDialog alert;                if (totalCount == 0) {                    Toast.makeText(this, "请选择要支付的商品", Toast.LENGTH_LONG).show();                    return;                }                alert = new AlertDialog.Builder(this).create();                alert.setTitle("操作提示");                alert.setMessage("总计:\n" + totalCount + "种商品\n" + totalPrice + "");                alert.setButton(DialogInterface.BUTTON_NEGATIVE, "取消",                        new DialogInterface.OnClickListener() {                            @Override                            public void onClick(DialogInterface dialog, int which) {                                return;                            }                        });                alert.setButton(DialogInterface.BUTTON_POSITIVE, "确定",                        new DialogInterface.OnClickListener() {                            @Override                            public void onClick(DialogInterface dialog, int which) {                            }                        });                alert.show();                break;        }    }    @Subscribe    public void onMessageEvent(MessageEvent event) {        allChekbox.setChecked(event.isChecked());    }    @Subscribe    public void onMessageEvent(PriceAndCountEvent event) {        title.setText("购物车(" + event.getCount() + ")");        tvGoToPay.setText("结算(" + event.getCount() + ")");        tvTotalPrice.setText("" + event.getPrice());        totalCount = event.getCount();        totalPrice = event.getPrice();    }}
ShopCartExListAdapter

public class ShopCartExListAdapter extends BaseExpandableListAdapter {    private Context context;    private List<SelCartBean.DataBean> list = new ArrayList<>();    private boolean isShow = true;    private boolean flag = true;    private int totalCount=0;    public ShopCartExListAdapter(Context context, List<SelCartBean.DataBean> list) {        this.context = context;        this.list = list;    }    @Override    public int getGroupCount() {        return list.size();    }    @Override    public int getChildrenCount(int i) {        return list.get(i).getList().size();    }    @Override    public Object getGroup(int i) {        return list.get(i);    }    @Override    public Object getChild(int i, int i1) {        return list.get(i).getList().get(i1);    }    @Override    public long getGroupId(int i) {        return i;    }    @Override    public long getChildId(int i, int i1) {        return i1;    }    @Override    public boolean hasStableIds() {        return false;    }    @Override    public View getGroupView(final int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {        View view;        final GroupViewHolder holder;        if (convertView == null) {            holder = new GroupViewHolder();            view = View.inflate(context,R.layout.item_shopcart_group, null);            holder.determine_chekbox = (CheckBox) view.findViewById(R.id.determine_chekbox);            holder.tv_source_name = (TextView) view.findViewById(R.id.tv_source_name);            holder.tv_store_edtor = (TextView) view.findViewById(R.id.tv_store_edtor);            view.setTag(holder);        } else {            view = convertView;            holder = (GroupViewHolder) view.getTag();        }        final SelCartBean.DataBean dataBean = list.get(groupPosition);        holder.determine_chekbox.setChecked(dataBean.isChecked());        holder.tv_source_name.setText(dataBean.getSellerName());        //一级checkbox        holder.determine_chekbox.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                totalCount++;                dataBean.setChecked(holder.determine_chekbox.isChecked());                changeChildCbState(groupPosition, holder.determine_chekbox.isChecked());                EventBus.getDefault().post(compute());                changeAllCbState(isAllGroupCbSelected());                notifyDataSetChanged();            }        });        if (dataBean.isEdtor()) {            holder.tv_store_edtor.setText("完成");        } else {            holder.tv_store_edtor.setText("编辑");        }        holder.tv_store_edtor.setOnClickListener(new GroupViewClick(groupPosition, holder.tv_store_edtor, dataBean));        notifyDataSetChanged();        return view;    }    @Override    public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {        View view;        final ChildViewHolder holder;        if (convertView == null) {            holder = new ChildViewHolder();            view = View.inflate(context,R.layout.item_shopcart_product, null);            holder.cbChild = (CheckBox) view.findViewById(R.id.check_box);            holder.tv_intro = (TextView) view.findViewById(R.id.tv_intro);            holder.imgIcon = (SimpleDraweeView) view.findViewById(R.id.iv_adapter_list_pic);            holder.tv_price = (TextView) view.findViewById(R.id.tv_price);            holder.tv_del = (TextView) view.findViewById(R.id.tv_goods_delete);//            holder.bt_add = (ImageView) view.findViewById(R.id.bt_add);//            holder.bt_del = (ImageView) view.findViewById(R.id.bt_reduce);//            holder.et_num = (EditText) view.findViewById(R.id.et_num);            holder.tv_num = (TextView) view.findViewById(R.id.tv_buy_num);            holder.ll_edtor = (LinearLayout) view.findViewById(R.id.ll_edtor);            holder.rl_no_edtor = (RelativeLayout) view.findViewById(R.id.rl_no_edtor);            holder.adv = view.findViewById(R.id.adv_main);            view.setTag(holder);        } else {            view = convertView;            holder = (ChildViewHolder) view.getTag();        }        final SelCartBean.DataBean.ListBean datasBean = list.get(groupPosition).getList().get(childPosition);        holder.cbChild.setChecked(datasBean.isChecked());        holder.tv_intro.setText(datasBean.getTitle());        holder.tv_price.setText(""+datasBean.getPrice() );        holder.tv_num.setText(datasBean.getNum() + "");//        holder.et_num.setText(datasBean.getNum() + "");        holder.adv.setNumber(datasBean.getNum());        String[] split = datasBean.getImages().split("[|]");        holder.imgIcon.setImageURI(Uri.parse(split[0]));        //二级checkbox        holder.cbChild.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                //设置该条目对象里的checked属性值                datasBean.setChecked(holder.cbChild.isChecked());                PriceAndCountEvent priceAndCountEvent = compute();                EventBus.getDefault().post(priceAndCountEvent);                if (holder.cbChild.isChecked()) {                    //当前checkbox是选中状态                    if (isAllChildCbSelected(groupPosition)) {                        changGroupCbState(groupPosition, true);                        changeAllCbState(isAllGroupCbSelected());                    }                    totalCount++;                } else {                    changGroupCbState(groupPosition, false);                    changeAllCbState(isAllGroupCbSelected());                }                notifyDataSetChanged();            }        });        holder.adv.setOnAddDelClickListener(new AddDeleteView.OnAddDelClickListener() {            @Override            public void onAddClick(View v) {                Log.i("zxz", "onAddClick: 执行");                int origin = holder.adv.getNumber();                origin++;//                holder.adv.setNumber(origin);                int num = datasBean.getNum();                num++;                holder.adv.setNumber(num);                datasBean.setNum(num);                if (holder.cbChild.isChecked()) {                    EventBus.getDefault().post(compute());                }            }            @Override            public void onDelClick(View v) {                int origin = holder.adv.getNumber();//                int num = datasBean.getNum();                origin--;                if (origin == 0) {                    Toast.makeText(context,"最小数量为1", Toast.LENGTH_SHORT).show();                    return ;                }                holder.adv.setNumber(origin);                datasBean.setNum(origin);                if (holder.cbChild.isChecked()) {                    EventBus.getDefault().post(compute());                }            }        });//        //加号//        holder.bt_add.setOnClickListener(new View.OnClickListener() {//            @Override//            public void onClick(View v) {//                int num = datasBean.getNum();//                ++num;//                holder.tv_num.setText(num + "");//                holder.et_num.setText(num +"");//                datasBean.setNum(num);//                if (holder.cbChild.isChecked()) {//                    PriceAndCountEvent priceAndCountEvent = compute();//                    EventBus.getDefault().post(priceAndCountEvent);//                }//            }//        });//        //减号//        holder.bt_del.setOnClickListener(new View.OnClickListener() {//            @Override//            public void onClick(View v) {//                int num = datasBean.getNum();//                if (num == 1) {//                    return;//                }//                --num;//                holder.tv_num.setText(num + "");//                holder.et_num.setText(num + "");//                datasBean.setNum(num);//                if (holder.cbChild.isChecked()) {//                    PriceAndCountEvent priceAndCountEvent = compute();//                    EventBus.getDefault().post(priceAndCountEvent);//                }//            }//        });        //删除        holder.tv_del.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                AlertDialog alert;                alert = new AlertDialog.Builder(context).create();                alert.setTitle("操作提示");                alert.setMessage("您确定要将这些商品从购物车中移除吗?");                alert.setButton(DialogInterface.BUTTON_NEGATIVE, "取消",                        new DialogInterface.OnClickListener() {                            @Override                            public void onClick(DialogInterface dialog, int which) {                                return;                            }                        });                alert.setButton(DialogInterface.BUTTON_POSITIVE, "确定",                        new DialogInterface.OnClickListener() {                            @Override                            public void onClick(DialogInterface dialog, int which) {                                List<SelCartBean.DataBean.ListBean> datasBeen = list.get(groupPosition).getList();                                SelCartBean.DataBean.ListBean remove = datasBeen.remove(childPosition);                                if (datasBeen.size() == 0) {                                    list.remove(groupPosition);                                }                                EventBus.getDefault().post(compute());                                notifyDataSetChanged();                            }                        });                alert.show();            }        });        //编辑        //判断是否在编辑状态下(标题中的编辑)        if (list.get(groupPosition).isEdtor() == true) {            holder.ll_edtor.setVisibility(View.VISIBLE);            holder.rl_no_edtor.setVisibility(View.GONE);        } else {            holder.ll_edtor.setVisibility(View.GONE);            holder.rl_no_edtor.setVisibility(View.VISIBLE);        }        return view;    }    @Override    public boolean isChildSelectable(int groupPosition, int childPosition) {        return true;    }    class GroupViewHolder {        CheckBox determine_chekbox;        TextView tv_source_name,tv_store_edtor;    }    /**     * 使某个组处于编辑状态     * <p/>     * groupPosition组的位置     */    class GroupViewClick implements View.OnClickListener {        private int groupPosition;        private TextView edtor;        private SelCartBean.DataBean group;        public GroupViewClick(int groupPosition, TextView edtor, SelCartBean.DataBean group) {            this.groupPosition = groupPosition;            this.edtor = edtor;            this.group = group;        }        @Override        public void onClick(View v) {            int groupId = v.getId();            if (groupId == edtor.getId()) {                if (group.isEdtor()) {                    group.setEdtor(false);                } else {                    group.setEdtor(true);                }                notifyDataSetChanged();            }        }    }    /**     * 监听编辑状态     */    public interface GroupEdtorListener {        void groupEdit(int groupPosition);    }    class ChildViewHolder {        CheckBox cbChild;        TextView tv_intro;        SimpleDraweeView imgIcon;        TextView tv_price;        TextView tv_del;        ImageView bt_del,bt_add;        EditText et_num;//        TextView tv_num;        LinearLayout ll_edtor;        RelativeLayout rl_no_edtor;        AddDeleteView adv;        ImageView iv_del;        ImageView iv_add;        TextView tv_num;    }    /**     * 改变全选的状态     *     * @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) {        SelCartBean.DataBean dataBean = list.get(groupPosition);        dataBean.setChecked(flag);    }    /**     * 改变二级列表checkbox状态     *     * @param groupPosition     * @param flag     */    private void changeChildCbState(int groupPosition, boolean flag) {        List<SelCartBean.DataBean.ListBean> datasBeen = list.get(groupPosition).getList();        for (int i = 0; i < datasBeen.size(); i++) {            SelCartBean.DataBean.ListBean datasBean = datasBeen.get(i);            datasBean.setChecked(flag);        }    }    /**     * 判断一级列表是否全部选中     *     * @return     */    private boolean isAllGroupCbSelected() {        for (int i = 0; i < list.size(); i++) {            SelCartBean.DataBean dataBean = list.get(i);            if (!dataBean.isChecked()) {                return false;            }        }        return true;    }    /**     * 判断二级列表是否全部选中     *     * @param groupPosition     * @return     */    private boolean isAllChildCbSelected(int groupPosition) {        List<SelCartBean.DataBean.ListBean> datasBeen = list.get(groupPosition).getList();        for (int i = 0; i < datasBeen.size(); i++) {            SelCartBean.DataBean.ListBean datasBean = datasBeen.get(i);            if (!datasBean.isChecked()) {                return false;            }        }        return true;    }    /**     * 计算列表中,选中的钱和数量     */    private PriceAndCountEvent compute() {        int count = 0;        int price = 0;        for (int i = 0; i < list.size(); i++) {            List<SelCartBean.DataBean.ListBean> datasBeen = list.get(i).getList();            for (int j = 0; j < datasBeen.size(); j++) {                SelCartBean.DataBean.ListBean datasBean = datasBeen.get(j);                if (datasBean.isChecked()) {                    price += datasBean.getNum() * datasBean.getPrice();                    count += datasBean.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 < list.size(); i++) {            changGroupCbState(i, flag);            changeChildCbState(i, flag);        }        EventBus.getDefault().post(compute());        notifyDataSetChanged();    }    /**     * 是否显示可编辑     *     * @param flag     */    public void isShow(boolean flag) {        isShow = flag;        notifyDataSetChanged();    }}

自定义加减器

AddDeleteView

public class AddDeleteView extends LinearLayout {    private OnAddDelClickListener listener;    private TextView et_number;    public void setOnAddDelClickListener(OnAddDelClickListener listener) {        if (listener != null) {            this.listener = listener;        }    }    public interface OnAddDelClickListener{        void onAddClick(View v);        void onDelClick(View v);    }    public AddDeleteView(Context context) {        this(context,null);    }    public AddDeleteView(Context context, @Nullable AttributeSet attrs) {        this(context, attrs,0);    }    public AddDeleteView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {        super(context, attrs, defStyleAttr);        initView(context,attrs,defStyleAttr);    }    private void initView(Context context,AttributeSet attrs,int defStyleAttr){        View.inflate(context, R.layout.layout_add_delete,this);        Button but_add = findViewById(R.id.but_add);        Button but_delete = findViewById(R.id.but_delete);        et_number = findViewById(R.id.et_number);        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.AddDeleteViewStyle);        String left_text = typedArray.getString(R.styleable.AddDeleteViewStyle_left_text);        String middle_text = typedArray.getString(R.styleable.AddDeleteViewStyle_middle_text);        String right_text = typedArray.getString(R.styleable.AddDeleteViewStyle_right_text);        et_number.setText(middle_text);        //释放资源        typedArray.recycle();        but_add.setOnClickListener(new OnClickListener() {            @Override            public void onClick(View view) {                listener.onAddClick(view);            }        });        but_delete.setOnClickListener(new OnClickListener() {            @Override            public void onClick(View view) {                listener.onDelClick(view);            }        });    }    /**     * 对外提供设置EditText值的方法     */    public void setNumber(int number){        if (number>0){            et_number.setText(number+"");        }    }    /**     * 得到控件原来的值     */    public int getNumber(){        int number = 0;        try {            String numberStr = et_number.getText().toString().trim();            number = Integer.valueOf(numberStr);        } catch (Exception e) {            number = 0;        }        return number;    }}
layout_add_delete.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent">    <LinearLayout        android:layout_width="match_parent"        android:layout_height="match_parent"        android:orientation="horizontal"        >        <Button            android:id="@+id/but_delete"            android:layout_width="22dp"            android:layout_height="22dp"            android:background="@mipmap/remove"            />        <TextView            android:id="@+id/et_number"            android:layout_width="40dp"            android:inputType="number"            android:layout_height="wrap_content"            android:gravity="center"            />        <Button            android:id="@+id/but_add"            android:layout_width="20dp"            android:layout_height="20dp"            android:background="@mipmap/add"            />    </LinearLayout></LinearLayout>


styles.xml

<declare-styleable name="AddDeleteViewStyle">    <attr name="left_text" format="string"/>    <attr name="right_text" format="string"/>    <attr name="middle_text" format="string"/></declare-styleable>

activity_main.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"    tools:context="bwie.com.zhouyafei.MainActivity">    <LinearLayout        android:id="@+id/top_bar"        android:layout_width="match_parent"        android:layout_height="48dp"        android:orientation="vertical" >        <RelativeLayout            android:layout_width="match_parent"            android:layout_height="48dp"            android:orientation="vertical" >            <ImageView                android:id="@+id/back"                android:layout_width="30dp"                android:layout_height="30dp"                android:layout_alignParentLeft="true"                android:layout_gravity="center_vertical"                android:layout_marginTop="10dp"                android:src="@mipmap/left" />            <TextView                android:id="@+id/title"                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:gravity="center"                android:minHeight="48dp"                android:text="购物车"                android:textColor="#1a1a1a"                android:textSize="16sp" />            <TextView                android:id="@+id/subtitle"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_alignParentRight="true"                android:layout_marginRight="20dp"                android:gravity="center"                android:minHeight="48dp"                android:text="编辑"                android:textColor="#1a1a1a"                android:textSize="14sp"                android:visibility="visible" />        </RelativeLayout>    </LinearLayout>    <FrameLayout        android:layout_width="match_parent"        android:layout_height="match_parent" >        <LinearLayout            android:id="@+id/ll_cart"            android:layout_width="match_parent"            android:layout_height="match_parent"            android:orientation="vertical"            >            <ExpandableListView                android:id="@+id/exListView"                android:layout_width="match_parent"                android:layout_height="0dp"                android:layout_weight="1"                android:childIndicator="@null"                android:groupIndicator="@null" >            </ExpandableListView>            <LinearLayout                android:layout_width="match_parent"                android:layout_height="50dp"                android:gravity="center_vertical"                android:orientation="horizontal" >                <CheckBox                    android:id="@+id/all_chekbox"                    android:layout_width="0dp"                    android:layout_height="wrap_content"                    android:layout_weight="1"                    android:layout_gravity="center_vertical"                    android:layout_marginRight="4dp"                    android:gravity="center"                    android:focusable="false"                    android:layout_marginLeft="10dp"                    android:text="全选"                    />                <LinearLayout                    android:id="@+id/ll_info"                    android:layout_width="0dp"                    android:layout_height="wrap_content"                    android:layout_weight="4"                    >                    <LinearLayout                        android:layout_width="match_parent"                        android:layout_height="wrap_content"                        android:orientation="vertical"                        android:layout_marginRight="20dp"                        android:layout_weight="1"                        >                        <LinearLayout                            android:layout_width="match_parent"                            android:layout_height="wrap_content"                            android:orientation="horizontal"                            android:gravity="right"                            >                            <TextView                                android:layout_width="wrap_content"                                android:layout_height="wrap_content"                                android:layout_marginLeft="5dp"                                android:text="合计:"                                android:textSize="18sp"                                android:textStyle="bold" />                            <TextView                                android:id="@+id/tv_total_price"                                android:layout_width="wrap_content"                                android:layout_height="wrap_content"                                android:text="0.00"                                android:textColor="#000"                                android:textSize="16sp"                                android:textStyle="bold" />                        </LinearLayout>                        <TextView                            android:layout_width="match_parent"                            android:layout_height="wrap_content"                            android:text="不含运费"                            android:gravity="right"                            android:textColor="#000"                            android:textSize="16sp"                            android:textStyle="bold" />                    </LinearLayout>                    <TextView                        android:id="@+id/tv_go_to_pay"                        android:layout_width="match_parent"                        android:layout_height="match_parent"                        android:layout_weight="3"                        android:background="#f00"                        android:clickable="true"                        android:gravity="center"                        android:text="结算(0)"                        android:textColor="#FAFAFA"                        />                </LinearLayout>                <LinearLayout                    android:id="@+id/ll_shar"                    android:layout_width="0dp"                    android:layout_height="match_parent"                    android:layout_weight="4"                    android:orientation="horizontal"                    android:visibility="gone"                    >                    <TextView                        android:id="@+id/tv_share"                        android:layout_width="match_parent"                        android:layout_height="match_parent"                        android:gravity="center"                        android:layout_weight="1"                        android:layout_marginLeft="5dp"                        android:text="分享宝贝"                        android:background="#ef930a"                        android:textColor="#fff"                        android:textSize="16sp"                        android:layout_marginRight="5dp"                        android:textStyle="bold" />                    <TextView                        android:id="@+id/tv_save"                        android:layout_width="match_parent"                        android:layout_height="match_parent"                        android:layout_weight="1"                        android:gravity="center"                        android:text="移到收藏夹"                        android:background="#ef930a"                        android:textColor="#fff"                        android:layout_marginRight="5dp"                        android:textSize="16sp"                        android:textStyle="bold" />                    <TextView                        android:id="@+id/tv_delete"                        android:layout_width="match_parent"                        android:layout_height="match_parent"                        android:layout_weight="1"                        android:background="#f00"                        android:clickable="true"                        android:gravity="center"                        android:text="删除"                        android:textColor="#FAFAFA"                        />                </LinearLayout>            </LinearLayout>        </LinearLayout>        <!--<include-->            <!--android:id="@+id/layout_cart_empty"-->            <!--android:layout_width="match_parent"-->            <!--android:layout_height="match_parent"-->            <!--layout="@layout/cart_empty"-->            <!--android:visibility="gone"/>-->    </FrameLayout></LinearLayout>

item_shopcart_group.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:orientation="vertical" >    <RelativeLayout        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:background="@android:color/white" >        <CheckBox            android:id="@+id/determine_chekbox"            android:layout_width="wrap_content"            android:layout_height="wrap_content"           android:layout_centerVertical="true"             />        <TextView            android:id="@+id/tv_source_name"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_centerVertical="true"            android:layout_marginBottom="10dp"            android:layout_marginTop="10dp"            android:layout_toRightOf="@id/determine_chekbox"            android:background="#ffffffff"            android:drawablePadding="10dp"            android:text="第八号当铺"            android:textColor="#000"            android:gravity="center"            android:textSize="18dp" />        <TextView            android:id="@+id/tv_store_edtor"            android:layout_width="50dp"            android:layout_height="wrap_content"            android:layout_alignParentRight="true"            android:layout_centerVertical="true"            android:layout_marginRight="14dp"            android:textSize="18dp"            android:background="@null"            android:text="编辑"/>    </RelativeLayout></LinearLayout>

item_shopcart_product.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:orientation="vertical" >    <View        android:layout_width="match_parent"        android:layout_height="1dp"        android:background="#CCCCCC" />    <LinearLayout        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:orientation="horizontal" >        <CheckBox            android:id="@+id/check_box"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_gravity="center_vertical"            android:layout_marginLeft="10dp"            android:layout_marginRight="4dp"            android:checkMark="?android:attr/listChoiceIndicatorMultiple"            android:gravity="center"            android:minHeight="64dp"            android:minWidth="32dp"            android:textAppearance="?android:attr/textAppearanceLarge"            android:visibility="visible" />        <com.facebook.drawee.view.SimpleDraweeView            android:id="@+id/iv_adapter_list_pic"            android:layout_width="85dp"            android:layout_height="85dp"            android:layout_marginBottom="15dp"            android:layout_marginTop="13dp"            android:scaleType="centerCrop"             />        <RelativeLayout            android:id="@+id/rl_no_edtor"            android:layout_width="wrap_content"            android:layout_height="match_parent"            android:layout_marginLeft="13dp"            >            <TextView                android:id="@+id/tv_intro"                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:layout_marginRight="10dp"                android:layout_marginTop="20dp"                android:ellipsize="end"                android:maxLines="2"                android:text="第八号店铺"                android:textColor="#000"                android:singleLine="true"                />            <TextView                android:id="@+id/tv_color_size"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="颜色:黑色;尺码:29"                android:layout_marginTop="5dp"                android:textColor="#000"                android:layout_centerVertical="true"                android:layout_alignParentLeft="true"                android:layout_alignParentStart="true" />            <RelativeLayout                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:orientation="horizontal"                android:layout_alignParentBottom="true"                android:layout_alignParentLeft="true"               android:layout_marginBottom="20dp"                android:layout_alignParentStart="true">                <TextView                    android:id="@+id/tv_price"                    android:layout_width="wrap_content"                    android:layout_height="wrap_content"                    android:layout_centerVertical="true"                    android:singleLine="true"                    android:text=" 308.00"                    android:textColor="#000"                    android:textStyle="bold" />                <TextView                    android:id="@+id/tv_discount_price"                    android:layout_width="wrap_content"                    android:layout_height="wrap_content"                    android:layout_centerVertical="true"                    android:layout_marginLeft="10dp"                    android:layout_toRightOf="@+id/tv_price"                    android:text=""                    />                <TextView                    android:id="@+id/tv_buy_num"                    android:layout_width="wrap_content"                    android:layout_height="wrap_content"                    android:layout_centerVertical="true"                    android:layout_marginRight="20dp"                    android:layout_alignParentRight="true"                    android:text="X 1"                    android:textColor="#000"                    />            </RelativeLayout>        </RelativeLayout>        <LinearLayout            android:id="@+id/ll_edtor"            android:layout_width="match_parent"            android:layout_height="match_parent"            android:layout_marginLeft="13dp"            android:visibility="gone"            android:orientation="horizontal">           <LinearLayout                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:layout_weight="1"                android:orientation="vertical">               <RelativeLayout                   android:id="@+id/ll_change_num"                   android:layout_width="match_parent"                   android:layout_height="wrap_content"                   android:gravity="center"                   android:layout_marginTop="20dp"                   android:orientation="horizontal">                   <bwie.com.zhouyafei.view.AddDeleteView                       android:id="@+id/adv_main"                       android:layout_width="wrap_content"                       android:layout_height="wrap_content">                       app:left_text="-"                       app:middle_text="3"                       app:right_text="+"                   </bwie.com.zhouyafei.view.AddDeleteView>                   <!--<ImageView-->                       <!--android:id="@+id/bt_reduce"-->                       <!--android:layout_width="20dp"-->                       <!--android:layout_height="50dp"-->                       <!--android:clickable="false"-->                       <!--android:focusableInTouchMode="false"-->                       <!--android:src="@mipmap/ic_reduce"-->                      <!--/>-->                   <!--<EditText-->                       <!--android:id="@+id/et_num"-->                       <!--android:layout_width="50dp"-->                       <!--android:layout_height="60dp"-->                       <!--android:inputType="number"-->                       <!--android:gravity="center"-->                       <!--android:focusableInTouchMode="true"-->                       <!--android:focusable="true"-->                       <!--android:text="1"-->                       <!--android:layout_alignBottom="@+id/bt_reduce"-->                       <!--android:layout_toEndOf="@+id/bt_reduce" />-->                   <!--<ImageView-->                       <!--android:id="@+id/bt_add"-->                       <!--android:layout_toRightOf="@id/et_num"-->                       <!--android:layout_width="20dp"-->                       <!--android:layout_height="50dp"-->                       <!--android:focusable="false"-->                       <!--android:focusableInTouchMode="false"-->                       <!--android:src="@mipmap/ic_add"-->                      <!--/>-->               </RelativeLayout>                <TextView                    android:id="@+id/tv_colorsize"                    android:layout_width="match_parent"                    android:layout_height="wrap_content"                    android:layout_marginTop="10dp"                    android:gravity="center"                    android:text="颜色:黑色;尺码:29"                    android:layout_gravity="left"                    android:textColor="#000"/>            </LinearLayout>           <TextView               android:id="@+id/tv_goods_delete"               android:layout_width="match_parent"               android:layout_height="match_parent"               android:layout_weight="3"               android:text="删除"               android:background="#ecb74c"               android:gravity="center"               android:layout_gravity="center"               android:textColor="#fff"/>        </LinearLayout>    </LinearLayout></LinearLayout>

原创粉丝点击