实现淘宝购物车功能

来源:互联网 发布:g92车螺纹编程实例 编辑:程序博客网 时间:2024/05/17 08:04

数据接口:

http://result.eolinker.com/iYXEPGn4e9c6dafce6e5cdd23287d2bb136ee7e9194d3e9?uri=evaluation

1:导入依赖

compile 'com.squareup.okhttp3:okhttp:3.9.0'compile 'com.squareup.okhttp3:logging-interceptor:3.9.0'compile 'com.google.code.gson:gson:2.8.2'compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'compile 'org.greenrobot:eventbus:3.1.1'
2:权限

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

3:bean包

public class GoosBean {    /**     * code : 200     * data : [{"datas":[{"add_time":"2016-12-10 14:54:58","cart_id":"445162","house_id":"1","msg":"购买渠道:大陆国行","price":99.9,"type_name":"苹果 iPhone 6(白金色)","type_sn_id":"ggh"},{"add_time":"2016-12-10 14:55:18","cart_id":"445163","house_id":"1","msg":"购买渠道:水货无锁","price":1000,"type_name":"苹果 iPhone 7 (亮黑色)","type_sn_id":"tgg"}],"title":"苹果","title_id":"59280"},{"datas":[{"add_time":"2016-12-10 14:54:58","cart_id":"445162","house_id":"1","msg":"边框背板:全新未使用","price":50,"type_name":"小米4s (白金色)","type_sn_id":"ggh"},{"add_time":"2016-12-10 14:55:18","cart_id":"445163","house_id":"1","msg":"屏幕性能:色差/亮点/轻微发黄","price":100,"type_name":"小米5s (亮黑色)","type_sn_id":"tgg"}],"title":"小米","title_id":"59279"},{"datas":[{"add_time":"2016-12-10 14:54:58","cart_id":"445162","house_id":"1","msg":"边框背板:全新未使用","price":50,"type_name":"三星 (白金色)","type_sn_id":"ggh"},{"add_time":"2016-12-10 14:55:18","cart_id":"445163","house_id":"1","msg":"屏幕性能:色差/亮点/轻微发黄","price":100,"type_name":"三星 (亮黑色)","type_sn_id":"tgg"}],"title":"三星","title_id":"59279"},{"datas":[{"add_time":"2016-12-10 14:54:58","cart_id":"445162","house_id":"1","msg":"边框背板:全新未使用","price":50,"type_name":"华为 (白金色)","type_sn_id":"ggh"},{"add_time":"2016-12-10 14:55:18","cart_id":"445163","house_id":"1","msg":"屏幕性能:色差/亮点/轻微发黄","price":100,"type_name":"华为 (亮黑色)","type_sn_id":"tgg"},{"add_time":"2016-12-10 4:55:28","cart_id":"445164","house_id":"1","msg":"屏幕性能:色差/亮点/轻微发黄","price":150,"type_name":"华为 (纯黑色)","type_sn_id":"hgg"}],"title":"华为","title_id":"59279"}]     * flag : Success     * msg : 描述     */    private String code;    private String flag;    private String msg;    private List<DataBean> data;    public String getCode() {        return code;    }    public void setCode(String code) {        this.code = code;    }    public String getFlag() {        return flag;    }    public void setFlag(String flag) {        this.flag = flag;    }    public String getMsg() {        return msg;    }    public void setMsg(String msg) {        this.msg = msg;    }    public List<DataBean> getData() {        return data;    }    public void setData(List<DataBean> data) {        this.data = data;    }    public static class DataBean {        /**         * datas : [{"add_time":"2016-12-10 14:54:58","cart_id":"445162","house_id":"1","msg":"购买渠道:大陆国行","price":500,"type_name":"苹果 iPhone 6(白金色)","type_sn_id":"ggh"},{"add_time":"2016-12-10 14:55:18","cart_id":"445163","house_id":"1","msg":"购买渠道:水货无锁","price":1000,"type_name":"苹果 iPhone 7 (亮黑色)","type_sn_id":"tgg"}]         * title : 苹果         * title_id : 59280         */        private boolean checked;        private String title;        private String title_id;        private List<DatasBean> datas;        public boolean isChecked() {            return checked;        }        public void setChecked(boolean checked) {            this.checked = checked;        }        public String getTitle() {            return title;        }        public void setTitle(String title) {            this.title = title;        }        public String getTitle_id() {            return title_id;        }        public void setTitle_id(String title_id) {            this.title_id = title_id;        }        public List<DatasBean> getDatas() {            return datas;        }        public void setDatas(List<DatasBean> datas) {            this.datas = datas;        }        public static class DatasBean {            /**             * add_time : 2016-12-10 14:54:58             * cart_id : 445162             * house_id : 1             * msg : 购买渠道:大陆国行             * price : 500             * type_name : 苹果 iPhone 6(白金色)             * type_sn_id : ggh             */            private boolean checked;            private int num = 1;            private String add_time;            private String cart_id;            private String house_id;            private String msg;            private int price;            private String type_name;            private String type_sn_id;            public int getNum() {                return num;            }            public void setNum(int num) {                this.num = num;            }            public boolean isChecked() {                return checked;            }            public void setChecked(boolean checked) {                this.checked = checked;            }            public String getAdd_time() {                return add_time;            }            public void setAdd_time(String add_time) {                this.add_time = add_time;            }            public String getCart_id() {                return cart_id;            }            public void setCart_id(String cart_id) {                this.cart_id = cart_id;            }            public String getHouse_id() {                return house_id;            }            public void setHouse_id(String house_id) {                this.house_id = house_id;            }            public String getMsg() {                return msg;            }            public void setMsg(String msg) {                this.msg = msg;            }            public int getPrice() {                return price;            }            public void setPrice(int price) {                this.price = price;            }            public String getType_name() {                return type_name;            }            public void setType_name(String type_name) {                this.type_name = type_name;            }            public String getType_sn_id() {                return type_sn_id;            }            public void setType_sn_id(String type_sn_id) {                this.type_sn_id = type_sn_id;            }        }    }}


4:

MessageEvent类里
public class MessageEvent {    private boolean checked;    public boolean isChecked() {        return checked;    }    public void setChecked(boolean checked) {        this.checked = checked;    }}


5:
PriceAndCountEvent 类里
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;    }}

6:model层 里面有两个 非别是一个接口和一个类
IMainModedl接口
public interface IMainModedl {    public void getGoods(OnNetListener<GoosBean> onNetListener);}
MainModel类需要继承IMainModel接口
public class MainModel implements IMainModedl{    private Handler handler = new Handler(Looper.getMainLooper());    @Override    public void getGoods( final OnNetListener<GoosBean> onNetListener) {        HttpUtils.getHttpUtils().doGet(Api.url, new Callback() {            @Override            public void onFailure(Call call, IOException e) {            }            @Override            public void onResponse(Call call, Response response) throws IOException {                String string = response.body().string();                final GoosBean goosBean = new Gson().fromJson(string, GoosBean.class);                handler.post(new Runnable() {                    @Override                    public void run() {                        onNetListener.onSuccess(goosBean);                    }                });            }        });    }}

7定义网络请求层分为三个7-1:
public interface Api {    public static final String url = "http://result.eolinker.com/iYXEPGn4e9c6dafce6e5cdd23287d2bb136ee7e9194d3e9?uri=evaluation";}
7-2:HttpUtils
public class HttpUtils {    private static volatile HttpUtils httpUtils;    private final OkHttpClient client;    private HttpUtils() {        HttpLoggingInterceptor logging = new HttpLoggingInterceptor();        logging.setLevel(HttpLoggingInterceptor.Level.BODY);        client = new OkHttpClient.Builder()                .addInterceptor(logging)                .build();    }    public static HttpUtils getHttpUtils() {        if (httpUtils == null) {            synchronized (HttpUtils.class) {                if (httpUtils == null) {                    httpUtils = new HttpUtils();                }            }        }        return httpUtils;    }    /**     * GET请求     *     * @param url     * @param callback     */    public void doGet(String url, Callback callback) {        Request request = new Request.Builder().url(url).build();        client.newCall(request).enqueue(callback);    }}
7-3:OnNetListener是一个接口
public interface OnNetListener<T> {    public void onSuccess(T t);    public void onFailure(Exception e);}

8:presenter类 定义
MainPresenter类
public class MainPresenter {    private final MainModel imainModel;    private final IMainActivity iMainActivity;    public MainPresenter(IMainActivity iMainActivity) {        this.iMainActivity = iMainActivity;        imainModel = new MainModel();    }    public void getGoods() {        imainModel.getGoods(new OnNetListener<GoosBean>() {            @Override            public void onSuccess(GoosBean goosBean) {                //List<GoosBean.DataBean> groupList, List<List<GoosBean.DataBean.DatasBean>> childList                List<GoosBean.DataBean> dataBean = goosBean.getData();                List<List<GoosBean.DataBean.DatasBean>> childList = new ArrayList<List<GoosBean.DataBean.DatasBean>>();                for (int i = 0; i < dataBean.size(); i++) {                    List<GoosBean.DataBean.DatasBean> datas = dataBean.get(i).getDatas();                    childList.add(datas);                }                iMainActivity.showList(dataBean, childList);            }            @Override            public void onFailure(Exception e) {            }        });    }}


9:view层 一个接口一个类:
IMainActivity接口
public interface IMainActivity {    public void showList(List<GoosBean.DataBean> groupList, List<List<GoosBean.DataBean.DatasBean>> childList);}
MainActivity类继承IMainActivity接口
public class MainActivity extends AppCompatActivity implements IMainActivity{    private ExpandableListView mElv;    private CheckBox mCheckbox2;    /**     * 0     */    private TextView mTvPrice;    /**     * 结算(0)     */    private TextView mTvNum;    private int totalCount;    private int totalPrice;    private MyAdapter adapter;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        EventBus.getDefault().register(this);        initView();        new MainPresenter(this).getGoods();        mCheckbox2.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                adapter.selectAllGroup(mCheckbox2.isChecked());            }        });    }    @Override    protected void onDestroy() {        super.onDestroy();        EventBus.getDefault().unregister(this);    }    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 showList(List<GoosBean.DataBean> groupList, List<List<GoosBean.DataBean.DatasBean>> childList) {        adapter = new MyAdapter(this, groupList, childList);        mElv.setAdapter(adapter);        mElv.setGroupIndicator(null);        //默认让其全部展开        for (int i = 0; i < groupList.size(); i++) {            mElv.expandGroup(i);        }    }    @Subscribe    public void onMessageEvent(MessageEvent event) {        mCheckbox2.setChecked(event.isChecked());    }    @Subscribe    public void onMessageEvent(PriceAndCountEvent event) {        totalCount += event.getCount();        totalPrice += event.getPrice();        mTvNum.setText("结算(" + totalCount + ")");        mTvPrice.setText(totalPrice + "");    }}

10:适配器 也是最重要的一个类
MyAdapter继承basexEpandableListAdapter
public class MyAdapter extends BaseExpandableListAdapter{    private Context context;    private List<GoosBean.DataBean> groupList;    private List<List<GoosBean.DataBean.DatasBean>> childList;    private final LayoutInflater inflater;    public MyAdapter(Context context, List<GoosBean.DataBean> groupList, List<List<GoosBean.DataBean.DatasBean>> childList) {        this.context = context;        this.groupList = groupList;        this.childList = childList;        inflater = LayoutInflater.from(context);    }    @Override    public int getGroupCount() {        return groupList.size();    }    @Override    public int getChildrenCount(int 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 groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {        View view;        final GroupViewHolder holder;        if (convertView == null) {            holder = new GroupViewHolder();            view = inflater.inflate(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 {            view = convertView;            holder = (GroupViewHolder) view.getTag();        }        final GoosBean.DataBean dataBean = groupList.get(groupPosition);        holder.cbGroup.setChecked(dataBean.isChecked());        holder.tv_number.setText(dataBean.getTitle());        //给holder.cbGroup设置点击事件        holder.cbGroup.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {               /* if (holder.cbGroup.isChecked()) {                    //点击的一级列表中的checkbox为选中状态                    selectChildAll(groupPosition, true);                } else {                    //点击的一级列表中的checkbox未选中状态                    selectChildAll(groupPosition, false);                }*/                dataBean.setChecked(holder.cbGroup.isChecked());                PriceAndCountEvent priceAndCountEvent = computePriceAndCount(holder.cbGroup.isChecked(), groupPosition);                selectChildAll(groupPosition, holder.cbGroup.isChecked());                //判断列表中的checkbox是否都选中                if (holder.cbGroup.isChecked()) {                    //点击的一节列表checkbox是选中状态                    setPriceAndCount(true, priceAndCountEvent.getPrice(), priceAndCountEvent.getCount());                    if (isAllGroupListChecked()) {                        //让“全选”为选中状态                        changeAllSelectState(true);                    }                } else {                    //点击的一节列表checkbox是未选中状态                    changeAllSelectState(false);                    setPriceAndCount(false, priceAndCountEvent.getPrice(), priceAndCountEvent.getCount());                }            }        });        return view;    }    @Override    public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {        View view;        final ChildViewHolder holder;        if (convertView == null) {            holder = new ChildViewHolder();            view = inflater.inflate(R.layout.item_child_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.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 {            view = convertView;            holder = (ChildViewHolder) view.getTag();        }        final GoosBean.DataBean.DatasBean datasBean = childList.get(groupPosition).get(childPosition);        holder.cbChild.setChecked(datasBean.isChecked());        holder.tv_tel.setText(datasBean.getType_name());        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() + "");        holder.tv_del.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                //删除                setPriceAndCount(false,datasBean.getPrice()*datasBean.getNum(),datasBean.getNum());                childList.get(groupPosition).remove(childPosition);                if (childList.get(groupPosition).size() == 0) {                    childList.remove(groupPosition);                    groupList.remove(groupPosition);                }                notifyDataSetChanged();            }        });        holder.iv_add.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                int num = datasBean.getNum();                datasBean.setNum(++num);                //判断当前checkbox是否选中                if (datasBean.isChecked()) {                    //把当前点击的条目对应的数量和钱,发送到MainActivity进行显示                    setPriceAndCount(true, datasBean.getPrice(), 1);                }                notifyDataSetChanged();            }        });        holder.iv_del.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                int num = datasBean.getNum();                if (num == 1) {                    return;                }                if (datasBean.isChecked()) {                    //把当前点击的条目对应的数量和钱,发送到MainActivity进行显示                    setPriceAndCount(false, datasBean.getPrice(), 1);                }                datasBean.setNum(--num);                notifyDataSetChanged();            }        });        //给holder.cbChild设置点击事件        holder.cbChild.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                //判断点击的checkbox是否选中                if (holder.cbChild.isChecked()) {                    //点击的时候,holder.cbChild是选中状态                    datasBean.setChecked(true);                    //把当前点击的条目对应的数量和钱,发送到MainActivity进行显示                    setPriceAndCount(true, datasBean.getPrice() * datasBean.getNum(), datasBean.getNum());                    if (isAllChildListChecked(groupPosition)) {                        GoosBean.DataBean dataBean = groupList.get(groupPosition);                        dataBean.setChecked(true);                        //判断一下其它的一级列表中的checkbox是否都选中,如果都选中则改变全选的状态                        if (isAllGroupListChecked()) {                            //去改变全选的状态                            changeAllSelectState(true);                        }                        notifyDataSetChanged();                    }                } else {                    //点击的时候,holder.cbChild是未选中状态                    datasBean.setChecked(false);                    //把当前点击的条目对应的数量和钱,发送到MainActivity进行显示                    setPriceAndCount(false, datasBean.getPrice() * datasBean.getNum(), datasBean.getNum());                    GoosBean.DataBean dataBean = groupList.get(groupPosition);                    dataBean.setChecked(false);                    //因为此时一级列表checkbox为未选中状态,所以,要把全选改成未选中                    changeAllSelectState(false);                    notifyDataSetChanged();                }            }        });        return view;    }    @Override    public boolean isChildSelectable(int groupPosition, int childPosition) {        return true;    }    class GroupViewHolder {        CheckBox cbGroup;        TextView tv_number;    }    class ChildViewHolder {        CheckBox cbChild;        TextView tv_tel;        TextView tv_content;        TextView tv_time;        TextView tv_price;        TextView tv_del;        ImageView iv_del;        ImageView iv_add;        TextView tv_num;    }    /**     * 点击一级列表时,计算钱和数量     */    private PriceAndCountEvent computePriceAndCount(boolean flag, int groupPoisiton) {        int count = 0;        int price = 0;        List<GoosBean.DataBean.DatasBean> datasBeen = childList.get(groupPoisiton);        for (int i = 0; i < datasBeen.size(); i++) {            GoosBean.DataBean.DatasBean datasBean = datasBeen.get(i);            if (flag) {                if (!datasBean.isChecked()) {                    count++;                    price += datasBean.getPrice();                }            } else {                if (datasBean.isChecked()) {                    count++;                    price += datasBean.getPrice();                }            }        }        PriceAndCountEvent priceAndCountEvent = new PriceAndCountEvent();        priceAndCountEvent.setPrice(price);        priceAndCountEvent.setCount(count);        return priceAndCountEvent;    }    /**     * 设置MainActiivty里的钱和数量     *     * @param isAdd     * @param price     * @param count     */    private void setPriceAndCount(boolean isAdd, int price, int count) {        PriceAndCountEvent priceAndCountEvent = new PriceAndCountEvent();        priceAndCountEvent.setCount(isAdd ? count : -count);        priceAndCountEvent.setPrice(isAdd ? price : -price);        EventBus.getDefault().post(priceAndCountEvent);    }    /**     * 改变MainActivity里的全选按钮状态     *     * @param isChecked     */    private void changeAllSelectState(boolean isChecked) {        MessageEvent messageEvent = new MessageEvent();        messageEvent.setChecked(isChecked);        EventBus.getDefault().post(messageEvent);    }    /**     * 判断一级列表是否全部选中     *     * @return     */    private boolean isAllGroupListChecked() {        for (int i = 0; i < groupList.size(); i++) {            GoosBean.DataBean dataBean = groupList.get(i);            if (!dataBean.isChecked()) {                return false;            }        }        return true;    }    /**     * 遍历二级列表数据,判断其它的checkbox是否也都选中     *     * @return     */    private boolean isAllChildListChecked(int groupPostion) {        List<GoosBean.DataBean.DatasBean> db = childList.get(groupPostion);        for (int i = 0; i < db.size(); i++) {            GoosBean.DataBean.DatasBean datasBean = db.get(i);            if (!datasBean.isChecked()) {                return false;            }        }        return true;    }    /**     * 设置二级列表是否全选     *     * @param groupPosition     * @param isSelectAll   true 表示全选 false 表示全不选     */    private void selectChildAll(int groupPosition, boolean isSelectAll) {        List<GoosBean.DataBean.DatasBean> datasBeen = childList.get(groupPosition);        for (int i = 0; i < datasBeen.size(); i++) {            GoosBean.DataBean.DatasBean datasBean = datasBeen.get(i);            datasBean.setChecked(isSelectAll);        }        notifyDataSetChanged();    }    public void selectAllGroup(boolean flag) {        int count = 0;        int price = 0;        //先把MainActivity里的数量和钱置为0,然后计算出所有的数量和钱就行了        for (int i = 0; i < groupList.size(); i++) {            List<GoosBean.DataBean.DatasBean> datasBeen = childList.get(i);            count += datasBeen.size();            for (int j = 0; j < datasBeen.size(); j++) {                price += datasBeen.get(j).getPrice();            }        }        setPriceAndCount(flag, price, count);        for (int i = 0; i < groupList.size(); i++) {            GoosBean.DataBean dataBean = groupList.get(i);            dataBean.setChecked(flag);            selectChildAll(i, flag);        }        notifyDataSetChanged();    }}接下来是布局文件主界面文件:
<TextView    android:layout_width="match_parent"    android:layout_height="40dp"    android:background="#990000ff"    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: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>


定义子布局文件:item_child_market
<CheckBox    android:id="@+id/cb_child"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:layout_marginBottom="30dp"    android:layout_marginLeft="40dp"    android:layout_marginTop="30dp"    android:focusable="false" /><LinearLayout    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:orientation="vertical">    <TextView        android:id="@+id/tv_tel"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_marginLeft="20dp"        android:text="iphone6" />    <TextView        android:id="@+id/tv_content"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_marginLeft="20dp"        android:text="什么手机" />    <TextView        android:id="@+id/tv_time"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_marginLeft="20dp"        android:text="2016-12-10" /></LinearLayout><LinearLayout    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:layout_weight="1"    android:orientation="vertical">    <TextView        android:id="@+id/tv_pri"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="¥3000.00" />    <LinearLayout        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:gravity="center_vertical">        <ImageView            android:id="@+id/iv_del"            android:layout_width="20dp"            android:layout_height="20dp"            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" />        <ImageView            android:id="@+id/iv_add"            android:layout_width="20dp"            android:layout_height="20dp"            android:layout_marginLeft="5dp"            android:src="@drawable/shopcart_add_red" />    </LinearLayout></LinearLayout><TextView    android:id="@+id/tv_del"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="删除" />


定义父布局文件:item_parent_market:
<CheckBox    android:id="@+id/cb_parent"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:layout_marginBottom="30dp"    android:layout_marginLeft="20dp"    android:layout_marginTop="30dp"    android:focusable="false" /><TextView    android:id="@+id/tv_sign"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:layout_marginLeft="20dp"    android:text="标记" /><TextView    android:id="@+id/tv_number"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:layout_marginLeft="20dp"    android:text="12345678" />