andriod——Retrofit+Fresco+MVP+解绑实现二级购物车

来源:互联网 发布:管家婆软件是什么 编辑:程序博客网 时间:2024/05/21 22:34


依赖包:
    //retrofit请求数据    compile 'com.squareup.retrofit2:retrofit:2.3.0'    compile 'com.squareup.retrofit2:converter-gson:2.3.0'    //Rxjava    compile 'io.reactivex.rxjava2:rxandroid:2.0.1'    compile 'io.reactivex.rxjava2:rxjava:2.1.7'    compile 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'    compile 'com.facebook.fresco:fresco:1.5.0'    compile 'com.android.support:recyclerview-v7:26.1.0'    compile 'org.greenrobot:eventbus:3.0.0'


adapter——UserAdapter

package com.example.gouwuche.adapter;import android.app.AlertDialog;import android.content.Context;import android.content.DialogInterface;import android.view.LayoutInflater;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 android.widget.Toast;import com.example.gouwuche.MyEvenBus.MessageEvent;import com.example.gouwuche.MyEvenBus.PriceAndCountEvent;import com.example.gouwuche.R;import com.example.gouwuche.bean.CartBean;import com.facebook.drawee.view.SimpleDraweeView;import org.greenrobot.eventbus.EventBus;import java.util.List;public class UserAdapter extends BaseExpandableListAdapter {    private Context context;    private List<CartBean.DataBean> groupList;    private List<List<CartBean.DataBean.ListBean>> childList;    private LayoutInflater inflater;    public UserAdapter(Context context, List<CartBean.DataBean> groupList, List<List<CartBean.DataBean.ListBean>> childList) {        this.context = context;        this.groupList = groupList;        this.childList = childList;        inflater=LayoutInflater.from(context);    }    @Override    public int getGroupCount() {        return groupList.size();    }    @Override    public int getChildrenCount(int groupPosition) {        return childList.get(groupPosition).size();    }    @Override    public Object getGroup(int groupPosition) {        return groupList.get(groupPosition);    }    @Override    public Object getChild(int groupPosition, int childPosition) {        return childList.get(groupPosition).get(childPosition);    }    @Override    public long getGroupId(int groupPosition) {        return groupPosition;    }    @Override    public long getChildId(int groupPosition, int childPosition) {        return childPosition;    }    @Override    public boolean hasStableIds() {        return 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_group, 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 CartBean.DataBean dataBean = groupList.get(groupPosition);        holder.cbGroup.setChecked(dataBean.isChecked());        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(groupPosition, holder.cbGroup.isChecked());                EventBus.getDefault().post(compute());                changeAllCbState(isAllGroupCbSelected());                notifyDataSetChanged();            }        });        return view;    }    @Override    public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, final View convertView, ViewGroup parent) {        View view;        final ChildViewHolder holder;        if (convertView == null) {            holder = new ChildViewHolder();            view = inflater.inflate(R.layout.item_child, 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);            holder.image=view.findViewById(R.id.simp);            view.setTag(holder);        } else {            view = convertView;            holder = (ChildViewHolder) view.getTag();        }        final CartBean.DataBean.ListBean datasBean = childList.get(groupPosition).get(childPosition);        holder.cbChild.setChecked(datasBean.isChecked());        holder.tv_tel.setText(datasBean.getTitle());        holder.tv_content.setText(datasBean.getSubhead());        holder.tv_time.setText(datasBean.getCreatetime());        holder.tv_price.setText(datasBean.getPrice() + "");        holder.tv_num.setText(datasBean.getNum() + "");        String[] split=datasBean.getImages().split("\\|");        holder.image.setImageURI(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());                    }                } else {                    changGroupCbState(groupPosition, 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()) {                    PriceAndCountEvent priceAndCountEvent = compute();                    EventBus.getDefault().post(priceAndCountEvent);                }            }        });        //减号        holder.iv_del.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                int num = datasBean.getNum();                if (num == 1) {                    Toast.makeText(context,"最小数量为1",Toast.LENGTH_LONG).show();                    return;                }                holder.tv_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) {                 /* @setIcon 设置对话框图标         * @setTitle 设置对话框标题         * @setMessage 设置对话框消息提示         * setXXX方法返回Dialog对象,因此可以链式设置属性         */                final AlertDialog.Builder normalDialog =                        new AlertDialog.Builder(context);                //normalDialog.setIcon(R.drawable.icon_dialog);                normalDialog.setTitle("操作提示");                normalDialog.setMessage("您确定要将商品移除购物车吗?");                normalDialog.setPositiveButton("确定",                        new DialogInterface.OnClickListener() {                            @Override                            public void onClick(DialogInterface dialog, int which) {                                List<CartBean.DataBean.ListBean> datasBeen = childList.get(groupPosition);                                CartBean.DataBean.ListBean remove = datasBeen.remove(childPosition);                                if (datasBeen.size() == 0) {                                    childList.remove(groupPosition);                                    groupList.remove(groupPosition);                                    Toast.makeText(context,"删除成功",Toast.LENGTH_SHORT).show();                                }                                Toast.makeText(context,"删除成功",Toast.LENGTH_SHORT).show();                                EventBus.getDefault().post(compute());                                notifyDataSetChanged();                            }                        });                normalDialog.setNegativeButton("关闭",                        new DialogInterface.OnClickListener() {                            @Override                            public void onClick(DialogInterface dialog, int which) {                                //...To-do                            }                        });                // 显示                normalDialog.show();            }        });        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;        SimpleDraweeView image;    }    /**     * 改变全选的状态     *     * @param flag     */    private void changeAllCbState(boolean flag) {        MessageEvent messageEvent = new MessageEvent();        messageEvent.setChecked(flag);        EventBus.getDefault().post(messageEvent);    }    /**     * 改变一级列表checkbox状态     *     * @param groupPosition     */    private void changGroupCbState(int groupPosition, boolean flag) {        CartBean.DataBean dataBean = groupList.get(groupPosition);        dataBean.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();    }}
bean——CartBean
package com.example.gouwuche.bean;import java.util.List;public class CartBean {    private String msg;    private String code;    private List<DataBean> data;    public String getMsg() {        return msg;    }    public void setMsg(String msg) {        this.msg = msg;    }    public String getCode() {        return code;    }    public void setCode(String code) {        this.code = code;    }    public List<DataBean> getData() {        return data;    }    public void setData(List<DataBean> data) {        this.data = data;    }    public static class DataBean {        private boolean checked;        private String sellerName;        private String sellerid;        private List<ListBean> list;        public boolean isChecked() {            return checked;        }        public void setChecked(boolean checked) {            this.checked = checked;        }        public String getSellerName() {            return sellerName;        }        public void setSellerName(String sellerName) {            this.sellerName = sellerName;        }        public String getSellerid() {            return sellerid;        }        public void setSellerid(String sellerid) {            this.sellerid = sellerid;        }        public List<ListBean> getList() {            return list;        }        public void setList(List<ListBean> list) {            this.list = list;        }        public static class ListBean {           private boolean checked;            private double bargainPrice;            private String createtime;            private String detailUrl;            private String images;            private int num;            private int pid;            private double price;            private int pscid;            private int selected;            private int sellerid;            private String subhead;            private String title;            public boolean isChecked() {                return checked;            }            public void setChecked(boolean checked) {                this.checked = checked;            }            public double getBargainPrice() {                return bargainPrice;            }            public void setBargainPrice(double bargainPrice) {                this.bargainPrice = bargainPrice;            }            public String getCreatetime() {                return createtime;            }            public void setCreatetime(String createtime) {                this.createtime = createtime;            }            public String getDetailUrl() {                return detailUrl;            }            public void setDetailUrl(String detailUrl) {                this.detailUrl = detailUrl;            }            public String getImages() {                return images;            }            public void setImages(String images) {                this.images = images;            }            public int getNum() {                return num;            }            public void setNum(int num) {                this.num = num;            }            public int getPid() {                return pid;            }            public void setPid(int pid) {                this.pid = pid;            }            public double getPrice() {                return price;            }            public void setPrice(double price) {                this.price = price;            }            public int getPscid() {                return pscid;            }            public void setPscid(int pscid) {                this.pscid = pscid;            }            public int getSelected() {                return selected;            }            public void setSelected(int selected) {                this.selected = selected;            }            public int getSellerid() {                return sellerid;            }            public void setSellerid(int sellerid) {                this.sellerid = sellerid;            }            public String getSubhead() {                return subhead;            }            public void setSubhead(String subhead) {                this.subhead = subhead;            }            public String getTitle() {                return title;            }            public void setTitle(String title) {                this.title = title;            }        }    }}

model——ShowModel
package com.example.gouwuche.model;import com.example.gouwuche.bean.CartBean;import com.example.gouwuche.newWork.OnNetListine;import com.example.gouwuche.newWork.RetrofitHolder;import io.reactivex.android.schedulers.AndroidSchedulers;import io.reactivex.functions.Consumer;import io.reactivex.schedulers.Schedulers;public class ShowModel {    public void getshow(final OnNetListine<CartBean> onNetListine){        RetrofitHolder.getApi().tags("android")                .subscribeOn(Schedulers.io())                .observeOn(AndroidSchedulers.mainThread())                .subscribe(new Consumer<CartBean>() {                    @Override                    public void accept(CartBean cartBean) throws Exception {                        onNetListine.OnSucc(cartBean);                    }                });    }}

MyEvenBus——MessageEvent
package com.example.gouwuche.MyEvenBus;public class MessageEvent {    private boolean checked;    public boolean isChecked() {        return checked;    }    public void setChecked(boolean checked) {        this.checked = checked;    }}
MyEvenBus——PriceAndCountEvent
package com.example.gouwuche.MyEvenBus;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;    }}

newWork——IDataInter
package com.example.gouwuche.newWork;import com.example.gouwuche.view.IMainActivity;//P层解绑public interface IDataInter<T extends IMainActivity> {    void attach(T view);    void detach();}
newWork——OnNetListine
package com.example.gouwuche.newWork;public interface OnNetListine<T> {   void OnSucc(T t);   void OnFile(String str);}
newWork——RetrofitHolder
package com.example.gouwuche.newWork;import okhttp3.OkHttpClient;import retrofit2.Retrofit;import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;import retrofit2.converter.gson.GsonConverterFactory;public class RetrofitHolder {    private static OkHttpClient okHttpClient;    private static ServesApi servesApi;    static {        initRetrofitHolder();    }    private static void initRetrofitHolder(){        if(okHttpClient==null){            synchronized (RetrofitHolder.class){                if(okHttpClient==null){                    okHttpClient=new OkHttpClient.Builder().build();                }            }        }    }    public static ServesApi getApi(){        if(servesApi==null){            synchronized (ServesApi.class){                if(servesApi==null){                    servesApi=RetrofitHolder.creatApi(ServesApi.class,UrlUtils.HOST);                }            }        }        return servesApi;    }    /**     *     * @param clazz     * @param url     * @param <T>     * @return     */    public static <T> T creatApi(Class<T> clazz,String url){        Retrofit retrofit = new Retrofit.Builder().baseUrl(UrlUtils.HOST)                .addConverterFactory(GsonConverterFactory.create())                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())                .build();        return retrofit.create(clazz);    }}
newWork——ServesApi
package com.example.gouwuche.newWork;import com.example.gouwuche.bean.CartBean;import io.reactivex.Flowable;import retrofit2.http.GET;import retrofit2.http.Query;public interface ServesApi {    //查询购物车    @GET(UrlUtils.TAG)    Flowable<CartBean> tags(@Query("source") String str);    //删除购物车    @GET(UrlUtils.DELETE)    Flowable<CartBean> delete();    //更新购物车购物车    @GET(UrlUtils.GEN)    Flowable<CartBean> GEN();}

newWork——UrlUtils
package com.example.gouwuche.newWork;public class UrlUtils {    public static final String HOST="http://120.27.23.105/";    //查询购物车    public static final String TAG="product/getCarts?uid=71";    //删除购物车    public static final String DELETE="product/deleteCart?uid=71&pid=1";    //更新购物车    public static final String GEN="product/updateCarts?uid=71&sellerid=1&pid=1&selected=0&num=10";}

prenester——ShowPrenester
package com.example.gouwuche.prenester;import com.example.gouwuche.bean.CartBean;import com.example.gouwuche.model.ShowModel;import com.example.gouwuche.newWork.IDataInter;import com.example.gouwuche.newWork.OnNetListine;import com.example.gouwuche.view.IMainActivity;import java.lang.ref.SoftReference;import java.util.ArrayList;import java.util.List;public class ShowPrenester implements IDataInter<IMainActivity> {    IMainActivity iMainActivity;    ShowModel showModel;    private SoftReference<IMainActivity> softReference;    public ShowPrenester(IMainActivity iMainActivity) {        attach(iMainActivity);        showModel=new ShowModel();    }    public void getshow(){        showModel.getshow(new OnNetListine<CartBean>() {            @Override            public void OnSucc(CartBean cartBean) {                List<CartBean.DataBean> data = cartBean.getData();                List<List<CartBean.DataBean.ListBean>> childlist=new ArrayList<List<CartBean.DataBean.ListBean>>();                for (int i = 0; i <data.size() ; i++) {                    List<CartBean.DataBean.ListBean> list = data.get(i).getList();                    childlist.add(list);                }               softReference.get().show(data,childlist);            }            @Override            public void OnFile(String str) {            }        });    }    @Override    public void attach(IMainActivity view) {        softReference=new SoftReference<IMainActivity>(view);    }    @Override    public void detach() {        softReference.clear();    }}

view——IMainActivity
package com.example.gouwuche.view;import com.example.gouwuche.bean.CartBean;import java.util.List;public interface IMainActivity {    public void show(List<CartBean.DataBean> grouplist, List<List<CartBean.DataBean.ListBean>> childlist);}

MainActivity
package com.example.gouwuche;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.widget.CheckBox;import android.widget.ExpandableListView;import android.widget.TextView;import com.example.gouwuche.MyEvenBus.MessageEvent;import com.example.gouwuche.MyEvenBus.PriceAndCountEvent;import com.example.gouwuche.adapter.UserAdapter;import com.example.gouwuche.bean.CartBean;import com.example.gouwuche.prenester.ShowPrenester;import com.example.gouwuche.view.IMainActivity;import org.greenrobot.eventbus.EventBus;import org.greenrobot.eventbus.Subscribe;import java.util.List;public class MainActivity  extends AppCompatActivity implements IMainActivity {    private ExpandableListView mElv;    private CheckBox mCheckbox2;    /**     * 0     */    private TextView mTvPrice;    /**     * 去支付(0)     */    private TextView mTvNum;    private UserAdapter userAdapter;    private ShowPrenester showPrenester;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        EventBus.getDefault().register(this);        initView();        showPrenester = new ShowPrenester(this);        showPrenester.getshow();        mCheckbox2.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                userAdapter.changeAllListCbState(mCheckbox2.isChecked());            }        });    }    @Override    public void show(List<CartBean.DataBean> grouplist, List<List<CartBean.DataBean.ListBean>> childlist) {        userAdapter = new UserAdapter(this, grouplist, childlist);        mElv.setAdapter(userAdapter);        mElv.setGroupIndicator(null);        //默认让其全部展开        for (int i = 0; i < grouplist.size(); i++) {            mElv.expandGroup(i);        }    }    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    protected void onDestroy() {        super.onDestroy();        EventBus.getDefault().unregister(this);        showPrenester.detach();    }    @Subscribe    public void onMessageEvent(MessageEvent event) {        mCheckbox2.setChecked(event.isChecked());    }    @Subscribe    public void onMessageEvent(PriceAndCountEvent event) {        mTvNum.setText("去支付(" + event.getCount() + ")");        mTvPrice.setText(event.getPrice() + "");    }}

MyApp
package com.example.gouwuche;import android.app.Application;import com.facebook.drawee.backends.pipeline.Fresco;public class MyApp extends Application{    @Override    public void onCreate() {        super.onCreate();        Fresco.initialize(this);    }}

AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET"/>
        android:name=".MyApp"
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">    <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></LinearLayout>

item_child.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout    xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:orientation="horizontal"    android:background="@android:color/darker_gray"    android:gravity="center_vertical"    android:layout_height="match_parent">    <CheckBox        android:id="@+id/cb_child"        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" /><com.facebook.drawee.view.SimpleDraweeView    android:id="@+id/simp"    android:layout_width="50dp"    android:layout_height="50dp"    android:background="@mipmap/ic_launcher"    />    <LinearLayout        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:orientation="vertical">        <TextView            android:id="@+id/tv_tel"            android:layout_width="30dp"            android:layout_height="30dp"            android:layout_marginLeft="20dp"            android:text="iphone6" />        <TextView            android:id="@+id/tv_content"            android:layout_width="30dp"            android:layout_height="30dp"            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="删除" /></LinearLayout>

item_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:gravity="center_vertical"    android:orientation="horizontal"    android:layout_height="100dp">    <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" /></LinearLayout>









原创粉丝点击