二级列表购物车++

来源:互联网 发布:仿生设计知乎 编辑:程序博客网 时间:2024/04/29 05:40
    结算的接口
package com.example.gshopping;
import com.example.gshopping.bean.ChildBean;import java.util.List;public interface MoneyView {    void isCheck(List<List<ChildBean>> list);

}

////////////////////////////////////////////mainactivity

package com.example.gshopping;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.util.Log;import android.view.View;import android.widget.CheckBox;import android.widget.ExpandableListView;import android.widget.TextView;
import com.example.gshopping.adapter.ExpandableAdapter;import com.example.gshopping.bean.ChildBean;import com.example.gshopping.bean.GroupBean;import com.example.gshopping.bean.Zbean;import com.example.gshopping.interfaces.Iview;import com.example.gshopping.persener.Persener;import java.util.ArrayList;import java.util.HashMap;import java.util.List;public class MainActivity extends AppCompatActivity implements Iview,MoneyView{    private Persener persener;    List<GroupBean> groupBeen=new ArrayList<>();    List<List<ChildBean>> childBeen=new ArrayList<>();    private ExpandableListView elv;    private CheckBox all_chekbox;    private TextView total_price;    private TextView totalnumber;    private ExpandableAdapter expandableAdapter;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        //获取控件        elv =(ExpandableListView)findViewById(R.id.elv);        all_chekbox =(CheckBox)findViewById(R.id.all_chekbox);        total_price =(TextView)findViewById(R.id.total_price);//价钱        totalnumber = (TextView)findViewById(R.id.total_number);//底部数量        //全选的点击事件        all_chekbox.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                //初始值                double money = 0;                //判断全选的check是否为选择状态                if(all_chekbox.isChecked()){                    //更改父子check状态                    for (int i=0;i<groupBeen.size();i++){                        groupBeen.get(i).setGropuCb(true);                        List<ChildBean> childBeen = MainActivity.this.childBeen.get(i);                        for(int x=0;x<childBeen.size();x++){                            childBeen.get(x).setChildCb(true);                            //计算全选的价格                            int num = childBeen.get(x).getNum();                            double price = childBeen.get(x).getPrice();                            money=money+num*price;                        }                    }                    //设置底部的价格money的显示                    total_price.setText(money+"");                }else{                    for (int i=0;i<groupBeen.size();i++){                        groupBeen.get(i).setGropuCb(false);                        List<ChildBean> childBeen = MainActivity.this.childBeen.get(i);                        for(int x=0;x<childBeen.size();x++){                            childBeen.get(x).setChildCb(false);                        }                    }                    total_price.setText(0+"");                }                expandableAdapter.notifyDataSetChanged();            }        });        //将P层对象创建出来        persener = new Persener();        persener.attach(this);        HashMap<String, String> map = new HashMap<>();        persener.get(" http://120.27.23.105/product/getCarts?uid=100",map,Zbean.class,"car");    }    //传过来数据之后进行获取并向集合添加    @Override    public void onSuccess(Object o, String tag) {         if (o!=null&&tag.equals("car")){             Zbean bean=(Zbean)o;             List<Zbean.DataBean> data = bean.getData();             for(Zbean.DataBean i:data){                 GroupBean groupBean = new GroupBean(i.getSellerName(), false);                 this.groupBeen.add(groupBean);                 //二级                 List<Zbean.DataBean.ListBean> list = i.getList();                 List<ChildBean> ls=new ArrayList<>();                 for(Zbean.DataBean.ListBean w:list){                     String[] split = w.getImages().toString().split("\\|");                     ChildBean childBean = new ChildBean(w.getTitle(), split[0], w.getPrice(), 1, false, false);                     ls.add(childBean);                 }                  this.childBeen.add(ls);             }             expandableAdapter = new ExpandableAdapter(MainActivity.this, groupBeen, childBeen,this);             elv.setAdapter(expandableAdapter);         }    }    @Override    public void onFailed(Exception e, String tag) {    }    //算钱的接口    @Override    public void isCheck(List<List<ChildBean>> list) {        double money=0;        for (int i=0;i<childBeen.size();i++){            List<ChildBean> childBeen = MainActivity.this.childBeen.get(i);            for(int x=0;x<childBeen.size();x++){                //计算全选的价格                if(childBeen.get(x).isChildCb()){                    int num = childBeen.get(x).getNum();                    double price = childBeen.get(x).getPrice();                    money=money+num*price;                }            }        }        //设置底部的价格money的显示        total_price.setText(money+"");    }}

/////////////////////////////////////////////////////自定义加减号
package com.example.gshopping;import android.content.Context;import android.support.annotation.Nullable;import android.util.AttributeSet;import android.view.View;import android.widget.LinearLayout;import android.widget.TextView;/** *  * 自定义View的加减号 */public class AddDeleteView extends LinearLayout {    //设置接口回调    private OnAddDelClickListener Listener;    private TextView etNumber;    public interface OnAddDelClickListener{        void onAddClick(View v);        void onDelClick(View v);    }    //接口对象    public void setOnAddDelClickListener(OnAddDelClickListener Listener){        if (Listener!=null){            this.Listener=Listener;        }    }    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);        //加载布局        View view = View.inflate(context, R.layout.zidingyiview, this);        //获得主键        TextView txtDelete = (TextView) findViewById(R.id.txt_delete);        TextView txtAdd = (TextView) findViewById(R.id.txt_add);        etNumber = (TextView) findViewById(R.id.et_number);        //点击事件        txtAdd.setOnClickListener(new OnClickListener() {            @Override            public void onClick(View v) {                Listener.onAddClick(AddDeleteView.this);            }        });        txtDelete.setOnClickListener(new OnClickListener() {            @Override            public void onClick(View v) {                Listener.onDelClick(AddDeleteView.this);            }        });    }    //对外提供设置EditText值得方法    public void setNumber(int number){        if (number>0){            etNumber.setText(number+"");        }    }    public int getNumber(){        int number=0;        try {            String trim = etNumber.getText().toString().trim();            number = Integer.valueOf(trim);        }catch (Exception e){            number=0;        }        return number;    }}
///////////////////////////////////////////////////
package com.example.gshopping.interfaces;public interface Iview {    void onSuccess(Object o,String tag);    void onFailed(Exception e,String tag);}
//////////////////////////////////////////////////
package com.example.gshopping.interfaces;public interface CallBack {    void onSuccess(Object o,String tag);    void onFailed(Exception e,String tag);}
//////////////////////////////////////////////////okhttp封装
package com.example.gshopping.httputils;import android.os.Handler;import com.example.gshopping.interfaces.CallBack;import com.google.gson.Gson;import java.io.IOException;import java.util.Map;import okhttp3.Call;import okhttp3.Callback;import okhttp3.FormBody;import okhttp3.OkHttpClient;import okhttp3.Request;import okhttp3.Response;public class HttpUtils {     private static volatile HttpUtils instance;         private static Handler handler = new Handler();         private HttpUtils(){         }         public static HttpUtils getInstance() {             if (instance == null) {                 synchronized (HttpUtils.class) {                     if (instance == null) {                         instance = new HttpUtils();                     }                 }             }             return instance;         }         //get请求         public void get(String url, Map<String,String> map, final CallBack callBack, final Class c,final String tag){             //对url和参数做拼接处理             StringBuffer stringBuffer = new StringBuffer();             stringBuffer.append(url);             //判断是否存在?   if中是存在             if(stringBuffer.indexOf("?")!=-1 ){                 //判断?是否在最后一位    if中是不在最后一位                 if(stringBuffer.indexOf("?")!=stringBuffer.length()-1){                     stringBuffer.append("&");                 }             }else{                 stringBuffer.append("?");             }             for(Map.Entry<String,String> entry:map.entrySet()){                 stringBuffer.append(entry.getKey())                         .append("=")                         .append(entry.getValue())                         .append("&");             }             //判断是否存在&   if中是存在             if(stringBuffer.indexOf("&")!=-1){                 stringBuffer.deleteCharAt(stringBuffer.lastIndexOf("&"));             }             //1:创建OkHttpClient对象             OkHttpClient okHttpClient = new OkHttpClient();             //2:创建Request对象             final Request request = new Request.Builder()                     .get()                     .url(stringBuffer.toString())                     .build();             //3:创建Call对象             Call call = okHttpClient.newCall(request);             //4:请求网络             call.enqueue(new Callback() {                 //请求失败                 @Override                 public void onFailure(Call call, final IOException e) {                     handler.post(new Runnable() {                         @Override                         public void run() {                             callBack.onFailed(e,tag);                         }                     });                 }                 //请求成功                 @Override                 public void onResponse(Call call, Response response) throws IOException {                     String result = response.body().string();                     //拿到数据解析                     final Object o = new Gson().fromJson(result, c);                     //当前是在子线程,回到主线程中                     handler.post(new Runnable() {                         @Override                         public void run() {                             //回调                             callBack.onSuccess(o,tag);                         }                     });                 }             });         }         //post请求         public void post(String url, Map<String,String> map, final CallBack callBack, final Class c,final String tag){             //1:创建OkHttpClient对象             OkHttpClient okHttpClient = new OkHttpClient();             //2:提供post请求需要的body对象             FormBody.Builder builder = new FormBody.Builder();             for(Map.Entry<String,String> entry:map.entrySet()){                 builder.add(entry.getKey(),entry.getValue());             }             FormBody body = builder.build();             //3:创建Request对象             final Request request = new Request.Builder()                     .post(body)                     .url(url)                     .build();             //4:创建Call对象             Call call = okHttpClient.newCall(request);             //5:请求网络             call.enqueue(new Callback() {                 //请求失败                 @Override                 public void onFailure(Call call, final IOException e) {                     handler.post(new Runnable() {                         @Override                         public void run() {                             callBack.onFailed(e,tag);                         }                     });                 }                 //请求成功                 @Override                 public void onResponse(Call call, Response response) throws IOException {                     String result = response.body().string();                     //拿到数据解析                     final Object o = new Gson().fromJson(result, c);                     //当前是在子线程,回到主线程中                     handler.post(new Runnable() {                         @Override                         public void run() {                             //回调                             callBack.onSuccess(o,tag);                         }                     });                 }             });         }}
////////////////////////////////////////////////////////
适配器
package com.example.gshopping.adapter;import android.content.Context;import android.util.Log;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.example.gshopping.AddDeleteView;import com.example.gshopping.MainActivity;import com.example.gshopping.MoneyView;import com.example.gshopping.R;import com.example.gshopping.bean.ChildBean;import com.example.gshopping.bean.GroupBean;import java.util.ArrayList;import java.util.List;/** * Created by on 2017/11/20. */public class ExpandableAdapter extends BaseExpandableListAdapter {    private Context context;    private List<GroupBean> groupBeen;    private  List<List<ChildBean>> childBeen;    private TextView shop_title;    private ImageView shop_img;    private TextView shop_price;    //实现该接口    private MoneyView moneyview;    public ExpandableAdapter(Context context, List<GroupBean> groupBeen, List<List<ChildBean>> childBeen,MoneyView moneyview) {        this.context = context;        this.groupBeen = groupBeen;        this.childBeen = childBeen;        this.moneyview = moneyview;    }    @Override    public int getGroupCount() {        return groupBeen.size();    }    @Override    public int getChildrenCount(int groupPosition) {        return childBeen.get(groupPosition).size();    }    @Override    public Object getGroup(int groupPosition) {        return groupBeen.get(groupPosition).getSellerName();    }    @Override    public Object getChild(int groupPosition, int childPosition) {        return childBeen.get(groupPosition).get(childPosition).getTitle();    }    @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 = View.inflate(context, R.layout.grouplist, null);        final CheckBox groupCb =(CheckBox)view.findViewById(R.id.group_checkbox);        TextView shopName = (TextView) view.findViewById(R.id.shop_name);        shopName.setText(groupBeen.get(groupPosition).getSellerName());        groupCb.setChecked(groupBeen.get(groupPosition).isGropuCb());        //一级的复选框        groupCb.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                //checked 一级的check                if(groupCb.isChecked()==true){                    //遍历子集合 让子集合中的Boolean值改为true                    List<ChildBean> childBeen1 = childBeen.get(groupPosition);                    for(int x=0;x<childBeen1.size();x++){                        childBeen1.get(x).setChildCb(true);                    }                    //改父级别的check的值                    groupBeen.get(groupPosition).setGropuCb(true);                    //刷新  重新加载                    notifyDataSetChanged();                    moneyview.isCheck(childBeen);                }else{                    List<ChildBean> childBeen1 = childBeen.get(groupPosition);                    for(int x=0;x<childBeen1.size();x++){                        childBeen1.get(x).setChildCb(false);                    }                    groupBeen.get(groupPosition).setGropuCb(false);                    notifyDataSetChanged();                }                //3全选设置                //得到Activity的全选按钮                MainActivity tag= (MainActivity) context;                CheckBox checkAll= (CheckBox) tag.findViewById(R.id.all_chekbox);               //设置一个初始的boolean值 用来判断                Boolean A=true;                //遍历父集合                for(int i=0;i<groupBeen.size();i++){                    boolean gropuCb = groupBeen.get(i).isGropuCb();                    if(gropuCb!=true){                        A=false;                        break;                    }                }                //设置全选按钮                checkAll.setChecked(A);                moneyview.isCheck(childBeen);            }        });        return view;    }    @Override    public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {        View view = View.inflate(context, R.layout.childlist, null);        final CheckBox childCheck= (CheckBox) view.findViewById(R.id.child_checkbox);        shop_title =(TextView)view.findViewById(R.id.shop_title);        shop_img =(ImageView)view.findViewById(R.id.shop_img);        shop_price =(TextView)view.findViewById(R.id.shop_price);        //找到自定义的View主键        final AddDeleteView adv= (AddDeleteView) view.findViewById(R.id.adddeleteview);        adv.setNumber(childBeen.get(groupPosition).get(childPosition).getNum());        adv.setOnAddDelClickListener(new AddDeleteView.OnAddDelClickListener() {            @Override            public void onAddClick(View v) {                int origin=adv.getNumber();                origin++;                adv.setNumber(origin);                //设置子check为true                childBeen.get(groupPosition).get(childPosition).setChildCb(true);                childBeen.get(groupPosition).get(childPosition).setNum(origin);                Log.e("TAG",origin+"");                notifyDataSetChanged();                moneyview.isCheck(childBeen);            }            @Override            public void onDelClick(View v) {                int origin=adv.getNumber();                origin--;                adv.setNumber(origin);                //设置子check为true                childBeen.get(groupPosition).get(childPosition).setChildCb(true);                childBeen.get(groupPosition).get(childPosition).setNum(origin);                notifyDataSetChanged();                moneyview.isCheck(childBeen);            }        });        shop_title.setText(childBeen.get(groupPosition).get(childPosition).getTitle());        String images = childBeen.get(groupPosition).get(childPosition).getImages();        Glide.with(context).load(images).into(shop_img);        shop_price.setText(childBeen.get(groupPosition).get(childPosition).getPrice()+"");        childCheck.setChecked(childBeen.get(groupPosition).get(childPosition).isChildCb());        //子级别的点击事件都点完之后  父级别根着动        childCheck.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                //得到子类里状态值                boolean childCb = childBeen.get(groupPosition).get(childPosition).isChildCb();                if(childCb){                    childBeen.get(groupPosition).get(childPosition).setChildCb(false);                }else{                    childBeen.get(groupPosition).get(childPosition).setChildCb(true);                }                //写一个变量值用来判断                Boolean A=true;                //遍历子集合                List<ChildBean> childBeen1 = childBeen.get(groupPosition);                for (int i=0;i<childBeen1.size();i++){                    //判断子级别中有没有false                    if(childBeen1.get(i).isChildCb()==false){                        A=false;                    }                }                //如果为true 子级别全选                if(A){                    //设置父级别的选择框                    groupBeen.get(groupPosition).setGropuCb(true);                }else{                    groupBeen.get(groupPosition).setGropuCb(false);                }                notifyDataSetChanged();                //子级别的全选按钮的判断设置                MainActivity tag= (MainActivity) context;                CheckBox checkAll= (CheckBox) tag.findViewById(R.id.all_chekbox);                //设置一个初始的boolean值 用来判断                Boolean B=true;                //遍历父集合                for(int x=0;x<childBeen.size();x++){                    List<ChildBean> childBeen = ExpandableAdapter.this.childBeen.get(x);                    for(int j=0;j<childBeen.size();j++){                        boolean childCb1 = childBeen.get(j).isChildCb();                        if(childCb1!=true){                            B=false;                            break;                        }                    }                }                //设置全选按钮                checkAll.setChecked(B);                moneyview.isCheck(childBeen);            }        });        return view;    }    @Override    public boolean isChildSelectable(int groupPosition, int childPosition) {        return false;    }}
////////////////////////////////////////////////////////////
package com.example.gshopping.bean;//子级需要的属性public class ChildBean {    private String title;    private String images;    private double price;    private int num;    private boolean childCb;    private boolean btn;    public ChildBean(String title, String images, double price, int num, boolean childCb, boolean btn) {        this.title = title;        this.images = images;        this.price = price;        this.num = num;        this.childCb = childCb;        this.btn = btn;    }    public String getTitle() {        return title;    }    public void setTitle(String title) {        this.title = title;    }    public String getImages() {        return images;    }    public void setImages(String images) {        this.images = images;    }    public double getPrice() {        return price;    }    public void setPrice(double price) {        this.price = price;    }    public int getNum() {        return num;    }    public void setNum(int num) {        this.num = num;    }    public boolean isChildCb() {        return childCb;    }    public void setChildCb(boolean childCb) {        this.childCb = childCb;    }    public boolean isBtn() {        return btn;    }    public void setBtn(boolean btn) {        this.btn = btn;    }}
//////////////////////////////////////////////

package com.example.gshopping.bean;//一级的商家和选框public class GroupBean {    private String sellerName;///    private boolean gropuCb;    public GroupBean(String sellerName, boolean gropuCb) {        this.sellerName = sellerName;        this.gropuCb = gropuCb;    }    public String getSellerName() {        return sellerName;    }    public void setSellerName(String sellerName) {        this.sellerName = sellerName;    }    public boolean isGropuCb() {        return gropuCb;    }    public void setGropuCb(boolean gropuCb) {        this.gropuCb = gropuCb;    }}
///////////////////////////////////////////////////////////

package com.example.gshopping.bean;import java.util.List;public class Zbean {    /**     * msg : 请求成功     * code : 0     * data : [{"list":[{"bargainPrice":22.9,"createtime":"2017-10-14T21:48:08","detailUrl":"https://item.m.jd.com/product/2542855.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t1930/284/2865629620/390243/e3ade9c4/56f0a08fNbd3a1235.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t2137/336/2802996626/155915/e5e90d7a/56f0a09cN33e01bd0.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t1882/31/2772215910/389956/c8dbf370/56f0a0a2Na0c86ea6.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t2620/166/2703833710/312660/531aa913/57709035N33857877.jpg!q70.jpg","num":2,"pid":24,"price":288,"pscid":2,"selected":0,"sellerid":1,"subhead":"三只松鼠零食特惠,专区满99减50,满199减100,火速抢购》","title":"三只松鼠 坚果炒货 零食奶油味 碧根果225g/袋"}],"sellerName":"商家1","sellerid":"1"},{"list":[{"bargainPrice":11800,"createtime":"2017-10-14T21:38:26","detailUrl":"https://item.m.jd.com/product/5025518.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t8830/106/1760940277/195595/5cf9412f/59bf2ef5N5ab7dc16.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5428/70/1520969931/274676/b644dd0d/591128e7Nd2f70da0.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5566/365/1519564203/36911/620c750c/591128eaN54ac3363.jpg!q70.jpg","num":1,"pid":58,"price":6399,"pscid":40,"selected":0,"sellerid":2,"subhead":"升级4G大显存!Nvme协议Pcie SSD,速度快人一步】GTX1050Ti就选拯救者!专业游戏键盘&新模具全新设计!","title":"联想(Lenovo)拯救者R720 15.6英寸游戏笔记本电脑(i5-7300HQ 8G 1T+128G SSD GTX1050Ti 4G IPS 黑)"},{"bargainPrice":6666,"createtime":"2017-10-10T16:01:31","detailUrl":"https://item.m.jd.com/product/5089273.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t8284/363/1326459580/71585/6d3e8013/59b857f2N6ca75622.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t9346/182/1406837243/282106/68af5b54/59b8480aNe8af7f5c.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8434/54/1359766007/56140/579509d9/59b85801Nfea207db.jpg!q70.jpg","num":1,"pid":46,"price":234,"pscid":39,"selected":0,"sellerid":2,"subhead":"【iPhone新品上市】新一代iPhone,让智能看起来更不一样","title":"Apple iPhone 8 Plus (A1864) 64GB 金色 移动联通电信4G手机"}],"sellerName":"商家2","sellerid":"2"},{"list":[{"bargainPrice":111.99,"createtime":"2017-10-14T21:39:05","detailUrl":"https://item.m.jd.com/product/4719303.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t9004/210/1160833155/647627/ad6be059/59b4f4e1N9a2b1532.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7504/338/63721388/491286/f5957f53/598e95f1N7f2adb87.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7441/10/64242474/419246/adb30a7d/598e95fbNd989ba0a.jpg!q70.jpg","num":85,"pid":10,"price":555.55,"pscid":1,"selected":0,"sellerid":3,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellerName":"商家3","sellerid":"3"},{"list":[{"bargainPrice":11800,"createtime":"2017-10-14T21:38:26","detailUrl":"https://mitem.jd.hk/ware/view.action?wareId=1988853309&cachekey=1acb07a701ece8d2434a6ae7fa6870a1","images":"https://m.360buyimg.com/n0/jfs/t6130/97/1370670410/180682/1109582a/593276b1Nd81fe723.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5815/178/2614671118/51656/7f52d137/593276c7N107b725a.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5878/60/2557817477/30873/4502b606/593276caN5a7d6357.jpg!q70.jpg","num":1,"pid":61,"price":14999,"pscid":40,"selected":0,"sellerid":5,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"}],"sellerName":"商家5","sellerid":"5"},{"list":[{"bargainPrice":159,"createtime":"2017-10-14T21:49:15","detailUrl":"https://item.m.jd.com/product/5061723.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t8716/197/1271594444/173291/2f40bb4f/59b743bcN8509428e.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8347/264/1286771527/92188/5cf5ec04/59b7420fN65378e9e.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7363/165/3000956253/190883/179a372/59b743bfNd0c79d93.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7399/112/2935531768/183594/b77c7d4a/59b7441aNc3d40133.jpg!q70.jpg","num":1,"pid":100,"price":2200,"pscid":112,"selected":0,"sellerid":11,"subhead":"针织针织闪闪闪亮你的眼","title":"维迩旎 2017秋冬新款长袖针织连衣裙韩版气质中长款名媛包臀A字裙 zx179709 黑色 XL"}],"sellerName":"商家11","sellerid":"11"},{"list":[{"bargainPrice":11800,"createtime":"2017-10-14T21:38:26","detailUrl":"https://mitem.jd.hk/ware/view.action?wareId=1988853309&cachekey=1acb07a701ece8d2434a6ae7fa6870a1","images":"https://m.360buyimg.com/n0/jfs/t6130/97/1370670410/180682/1109582a/593276b1Nd81fe723.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5815/178/2614671118/51656/7f52d137/593276c7N107b725a.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5878/60/2557817477/30873/4502b606/593276caN5a7d6357.jpg!q70.jpg","num":1,"pid":69,"price":16999,"pscid":40,"selected":0,"sellerid":13,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"}],"sellerName":"商家13","sellerid":"13"},{"list":[{"bargainPrice":111.99,"createtime":"2017-10-14T21:39:05","detailUrl":"https://item.m.jd.com/product/4719303.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t9004/210/1160833155/647627/ad6be059/59b4f4e1N9a2b1532.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7504/338/63721388/491286/f5957f53/598e95f1N7f2adb87.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7441/10/64242474/419246/adb30a7d/598e95fbNd989ba0a.jpg!q70.jpg","num":1,"pid":1,"price":118,"pscid":1,"selected":0,"sellerid":17,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellerName":"商家17","sellerid":"17"},{"list":[{"bargainPrice":111.99,"createtime":"2017-10-14T21:39:05","detailUrl":"https://item.m.jd.com/product/4719303.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t9004/210/1160833155/647627/ad6be059/59b4f4e1N9a2b1532.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7504/338/63721388/491286/f5957f53/598e95f1N7f2adb87.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7441/10/64242474/419246/adb30a7d/598e95fbNd989ba0a.jpg!q70.jpg","num":1,"pid":2,"price":299,"pscid":1,"selected":0,"sellerid":18,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellerName":"商家18","sellerid":"18"}]     */    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 {        /**         * list : [{"bargainPrice":22.9,"createtime":"2017-10-14T21:48:08","detailUrl":"https://item.m.jd.com/product/2542855.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t1930/284/2865629620/390243/e3ade9c4/56f0a08fNbd3a1235.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t2137/336/2802996626/155915/e5e90d7a/56f0a09cN33e01bd0.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t1882/31/2772215910/389956/c8dbf370/56f0a0a2Na0c86ea6.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t2620/166/2703833710/312660/531aa913/57709035N33857877.jpg!q70.jpg","num":2,"pid":24,"price":288,"pscid":2,"selected":0,"sellerid":1,"subhead":"三只松鼠零食特惠,专区满99减50,满199减100,火速抢购》","title":"三只松鼠 坚果炒货 零食奶油味 碧根果225g/袋"}]         * sellerName : 商家1         * sellerid : 1         */        private String sellerName;        private String sellerid;        private List<ListBean> list;        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 {            /**             * bargainPrice : 22.9             * createtime : 2017-10-14T21:48:08             * detailUrl : https://item.m.jd.com/product/2542855.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends             * images : https://m.360buyimg.com/n0/jfs/t1930/284/2865629620/390243/e3ade9c4/56f0a08fNbd3a1235.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t2137/336/2802996626/155915/e5e90d7a/56f0a09cN33e01bd0.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t1882/31/2772215910/389956/c8dbf370/56f0a0a2Na0c86ea6.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t2620/166/2703833710/312660/531aa913/57709035N33857877.jpg!q70.jpg             * num : 2             * pid : 24             * price : 288.0             * pscid : 2             * selected : 0             * sellerid : 1             * subhead : 三只松鼠零食特惠,专区满99减50,满199减100,火速抢购》             * title : 三只松鼠 坚果炒货 零食奶油味 碧根果225g/袋             */            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 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;            }        }    }}
///////////////////////////////////////////////////布局activity_main.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"    android:orientation="vertical">    <ExpandableListView        android:id="@+id/elv"        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_marginLeft="20dp"            android:layout_width="wrap_content"            android:layout_height="wrap_content" />        <TextView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            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/total_price"                        android:layout_width="wrap_content"                        android:layout_height="wrap_content"                        android:text="¥0.00"                        android:textColor="#f23232"                        android:textSize="16sp"                        android:textStyle="bold" />                </LinearLayout>                <TextView                    android:id="@+id/total_number"                    android:layout_width="match_parent"                    android:layout_height="wrap_content"                    android:text="共有商品:0件"                    android:gravity="right"                    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="#fd7a05"                android:clickable="true"                android:gravity="center"                android:text="结算"                android:textColor="#FAFAFA"                />        </LinearLayout>    </LinearLayout>///////////////////////////////////////////////////////////////childlist_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:layout_height="match_parent">    <CheckBox        android:id="@+id/child_checkbox"        android:layout_width="0dp"        android:layout_height="wrap_content"        android:layout_weight="1"        />    <LinearLayout        android:layout_width="0dp"        android:layout_height="wrap_content"        android:orientation="vertical"        android:layout_weight="9">        <TextView            android:id="@+id/shop_title"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_marginLeft="17dp"            android:layout_marginStart="17dp"            android:text="TextView" />        <LinearLayout            android:layout_width="match_parent"            android:orientation="horizontal"            android:layout_height="match_parent">        <ImageView            android:id="@+id/shop_img"            android:layout_width="90dp"            android:layout_height="90dp"            android:layout_marginTop="30dp" />            <LinearLayout                android:layout_width="match_parent"                android:layout_height="match_parent"                android:orientation="vertical">                <TextView                    android:id="@+id/shop_price"                    android:layout_width="match_parent"                    android:layout_height="wrap_content"                    android:layout_marginTop="10dp"                    android:gravity="center"                    android:textSize="25dp"                    android:text="¥20"                    android:textColor="#f23232" />                <com.example.gshopping.AddDeleteView                    android:layout_width="match_parent"                    android:layout_height="wrap_content"                    android:id="@+id/adddeleteview"                    android:gravity="center"></com.example.gshopping.AddDeleteView>            </LinearLayout>        </LinearLayout>    </LinearLayout></LinearLayout>
/////////////////////////////////////////////////////////////grouplist.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:layout_height="match_parent">    <CheckBox        android:id="@+id/group_checkbox"        android:layout_marginLeft="20dp"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:focusable="false"/>    <TextView        android:id="@+id/shop_name"        android:layout_marginLeft="20dp"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:textSize="16dp" />
</LinearLayout>
/////////////////////////////////////////////////////zidingyiview.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:layout_height="match_parent">    <TextView        android:layout_width="0dp"        android:layout_height="match_parent"        android:layout_weight="1"        android:text="减"        android:gravity="center"        android:textSize="20dp"        android:id="@+id/txt_delete"        />    <TextView        android:layout_width="0dp"        android:layout_height="match_parent"        android:id="@+id/et_number"        android:layout_weight="3"        android:gravity="center"        android:textSize="20dp"        android:text="1"        />    <TextView        android:layout_width="0dp"        android:layout_height="match_parent"        android:layout_weight="1"        android:text="加"        android:gravity="center"        android:id="@+id/txt_add"        android:textSize="20dp"        /></LinearLayout>


原创粉丝点击