android_购物车
来源:互联网 发布:javascript var 对象 编辑:程序博客网 时间:2024/06/05 14:28
//layout_tile头部
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/colorAccent" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="25sp" android:padding="10dp" android:id="@+id/btnBack" android:text="返回"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="购物车" android:textSize="25sp" android:layout_weight="1" android:gravity="center" android:padding="10dp" android:layout_gravity="center_horizontal"/> <TextView android:padding="10dp" android:textSize="25sp" android:id="@+id/btnEditor" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="编辑"/></LinearLayout>
//layot_shopping_car_bottom 底部
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <CheckBox android:id="@+id/chooseAll" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="25sp" android:padding="10dp" android:text="全选"/> <TextView android:id="@+id/totalPrice" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="25sp" android:layout_weight="1" android:padding="10dp" android:gravity="center" android:text="合计:0.00 ¥"/> <TextView android:id="@+id/btnAmount" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="结算 : (0)" android:gravity="center" android:background="@android:color/holo_orange_light" android:textColor="@android:color/black" android:textSize="25sp" android:padding="10dp"/></LinearLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content"> <CheckBox android:id="@+id/ck_chose" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_marginLeft="5dp" android:scaleX="0.6" android:scaleY="0.6" /> <ImageView android:id="@+id/iv_show_pic" android:layout_width="70dp" android:layout_height="80dp" android:layout_centerVertical="true" android:layout_marginLeft="5dp" android:background="@mipmap/ic_launcher" android:layout_toRightOf="@id/ck_chose" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:layout_marginTop="15dp" android:layout_toRightOf="@id/iv_show_pic" android:orientation="vertical"> <TextView android:id="@+id/tv_commodity_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="酒红色纯红色纯羊毛西服套装" android:textColor="@android:color/black" android:textSize="12sp" android:textStyle="bold" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:id="@+id/tv_commodity_attr" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="3dp" android:text="属性:粉蓝色" android:textSize="12sp" android:textColor="@color/colorPrimary" /> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="4dp" android:orientation="horizontal"> <TextView android:id="@+id/tv_commodity_price" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="¥390" android:textColor="@android:color/holo_red_dark" android:textSize="12sp" android:textStyle="bold" /> <TextView android:id="@+id/tv_commodity_num" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="20dp" android:text="x1" android:textColor="@android:color/darker_gray" /> <LinearLayout android:id="@+id/rl_edit" android:layout_width="160dp" android:background="@android:color/holo_orange_light" android:layout_height="30dp" android:layout_marginLeft="20dp" > <TextView android:id="@+id/iv_sub" android:layout_width="0dp" android:layout_weight="1" android:gravity="center" android:textColor="@android:color/black" android:background="@android:color/white" android:layout_margin="1dp" android:layout_height="match_parent" android:text=" - " /> <TextView android:id="@+id/tv_commodity_show_num" android:layout_width="0dp" android:layout_height="match_parent" android:layout_margin="1dp" android:layout_weight="1" android:background="@android:color/white" android:gravity="center" android:text="1" /> <TextView android:id="@+id/iv_add" android:layout_width="0dp" android:layout_weight="1" android:gravity="center" android:layout_margin="1dp" android:background="@android:color/white" android:layout_height="match_parent" android:text=" + " /> <ImageView android:id="@+id/btn_commodity_delete" android:layout_width="0dp" android:layout_weight="2" android:src="@drawable/jsbundles_jdreactaftersales_images_multimedia_delete" android:layout_height="wrap_content" /> </LinearLayout> </LinearLayout> </LinearLayout></RelativeLayout>
//twoleveedyi 容器
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content"> <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/fucheckbox"/> <TextView android:id="@+id/furongqi" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="25dp"/> </LinearLayout></LinearLayout>
//activity_shoppingcar 整体合一
<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:orientation="vertical" android:layout_height="match_parent" tools:context="com.example.gwc.Shoppingcar"> <include layout="@layout/layout_tile"> </include> <ExpandableListView android:id="@+id/carListView" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1"> </ExpandableListView> <View android:layout_width="match_parent" android:layout_height="0.5dp" android:background="@android:color/background_dark"/> <include layout="@layout/layot_shopping_car_bottom"> </include></LinearLayout>
//Shoppingcar Main类绘制整体布局
package com.example.gwc;import android.content.Intent;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.util.Log;import android.view.View;import android.widget.CheckBox;import android.widget.ExpandableListView;import android.widget.TextView;import android.widget.Toast;import com.example.gwc.Myshopingcar.Carbean;import com.example.gwc.Myshopingcar.Carinit;import com.example.gwc.Myshopingcar.Carpersonlei;import com.example.gwc.Myshopingcar.Carsonbean;import com.example.gwc.adapter.shopingcaradapter;import com.example.gwc.myokhttp.EdOkthhp;import com.example.gwc.sylei.MessageEvent;import com.example.gwc.sylei.PriceAndCountEvent;import com.example.gwc.twoxaingqing.Okinteface;import org.greenrobot.eventbus.EventBus;import org.greenrobot.eventbus.Subscribe;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;public class Shoppingcar extends AppCompatActivity implements Carinit { private ExpandableListView carlistview; private Carpersonlei carpersonlei; private ArrayList<Carbean.DataBean> fu_list = new ArrayList<>(); private ArrayList<List<Carbean.DataBean.ListBean>> zi_list = new ArrayList<>(); private TextView totalprice; private CheckBox chooseall; private ArrayList<Carsonbean> carsonbeen = new ArrayList<>();; private TextView price; private String s; private String jsprice; private String jsnum; private Carbean ss; private TextView jiesuan; private TextView btneditor; private List<Carbean.DataBean> data; private com.example.gwc.adapter.shopingcaradapter shopingcaradapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_shoppingcar); carlistview = (ExpandableListView) findViewById(R.id.carListView); totalprice = (TextView) findViewById(R.id.totalPrice); chooseall = (CheckBox) findViewById(R.id.chooseAll); price = (TextView) findViewById(R.id.totalPrice); jiesuan = (TextView) findViewById(R.id.btnAmount); carpersonlei = new Carpersonlei(this); EventBus.getDefault().register(this); //点击结算 jiesuan.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(Shoppingcar.this, JiesuanActivity.class); intent.putExtra("jiaqian",jsprice); intent.putExtra("shuliang",jsnum);// Toast.makeText(Shoppingcar.this,jsprice,Toast.LENGTH_SHORT).show();// startActivity(intent); startActivityForResult(intent,1); } }); btneditor = (TextView) findViewById(R.id.btnEditor); //点击编辑 btneditor.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if(btneditor.getText().toString().trim().equals("编辑")){ if(!(shopingcaradapter==null)){ shopingcaradapter.flog=true; shopingcaradapter.notifyDataSetChanged(); } btneditor.setText("完成"); }else { if(!(shopingcaradapter==null)) { shopingcaradapter.flog=false; shopingcaradapter.notifyDataSetChanged(); } btneditor.setText("编辑"); } } }); //全选/全不选 chooseall.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //设置全选 shopingcaradapter.changeAllListCbState(chooseall.isChecked()); } }); s = "http://120.27.23.105/product/getCarts?source=android&uid=3515"; carpersonlei.edcanshu(s); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); for (int i = 0; i < fu_list.size(); i++) { List<Carbean.DataBean.ListBean> list = fu_list.get(i).getList(); for(int j=0;j<list.size();j++){ boolean checked = list.get(j).isChecked(); if(checked) { Map<String, String> map = new HashMap(); map.put("uid", 3515 + ""); map.put("price", list.get(j).getPrice() + ""); EdOkthhp.getInert().doGet("http://120.27.23.105/product/createOrder", map, new Okinteface() { @Override public void chenggong(String cheng) { Log.e("chen", "chenggong:创建成功 " + cheng); } @Override public void shibai(String shi) { Log.e("chen", "chenggong:创建失败 " + shi); } }); } } } Intent intent = new Intent(Shoppingcar.this, DingdanActivity.class); startActivity(intent); } @Subscribe public void onMessageEvent(MessageEvent event) { chooseall.setChecked(event.isCheckd()); } @Subscribe public void onMessageEven(PriceAndCountEvent event) { int price = event.getPrice(); jsprice = price+""; this.price.setText("总价" +price ); jsnum = event.getTo()+""; // num.setText("共" + event.getCount() + "件商品"); jiesuan.setText("结算: ("+event.getTo()+")"); } @Override public void seecss(Carbean bean) { ss = bean; //获取数据源 if(bean==null){// show.setVisibility(View.VISIBLE); Toast.makeText(Shoppingcar.this, "购物车为空,快去买东西吧",Toast.LENGTH_SHORT).show(); }else {// fu_list.clear();// zi_list.clear(); data = bean.getData(); fu_list.addAll(data); for (int i = 0; i< data.size(); i++){ List<Carbean.DataBean.ListBean> list = data.get(i).getList(); zi_list.add(list); } shopingcaradapter = new shopingcaradapter(Shoppingcar.this, fu_list, zi_list); //shuzg-hi适配器 carlistview.setAdapter(shopingcaradapter); //让二级列表进行展开, int groupCount = carlistview.getCount(); for (int i = 0; i < groupCount; i++) { carlistview.expandGroup(i); } } } @Override public void faild(String shib) { Log.e("chen", "seecss: 我是购物车"+shib ); }}
//shopingcaradapter 购物车的适配器
package com.example.gwc.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 android.widget.Toast;import com.bumptech.glide.Glide;import com.example.gwc.Myshopingcar.Carbean;import com.example.gwc.Myshopingcar.Mydeleteshopping.Cardeletepersonlei;import com.example.gwc.Myshopingcar.Mydeleteshopping.Deletecarinit;import com.example.gwc.R;import com.example.gwc.sylei.MessageEvent;import com.example.gwc.sylei.PriceAndCountEvent;import org.greenrobot.eventbus.EventBus;import java.util.ArrayList;import java.util.List;public class shopingcaradapter extends BaseExpandableListAdapter { private Context context; private ArrayList<Carbean.DataBean> data1; private ArrayList<List<Carbean.DataBean.ListBean>> data2; private Boolean flag = false; public static boolean flog; public shopingcaradapter(Context context, ArrayList<Carbean.DataBean> data1, ArrayList<List<Carbean.DataBean.ListBean>> data2) { this.context = context; this.data1 = data1; this.data2 = data2; Log.e("chen", "shopingcaradapter:我是适配器的值 "+data1+data2 ); } @Override public int getGroupCount() { return data1.size(); } @Override public int getChildrenCount(int i) { return data2.get(i).size(); } @Override public Object getGroup(int i) { return data1.get(i); } @Override public Object getChild(int i, int i1) { return data2.get(i).get(i1); } @Override public long getGroupId(int i) { return i; } @Override public long getChildId(int i, int i1) { return i1; } @Override public boolean hasStableIds() { return false; } @Override public View getGroupView(final int i, boolean b, View view, ViewGroup viewGroup) { View inflate = View.inflate(context, R.layout.twoleveedyi,null); TextView furongqi = inflate.findViewById(R.id.furongqi); furongqi.setText(data1.get(i).getSellerName()); final CheckBox fuche = inflate.findViewById(R.id.fucheckbox); fuche.setChecked(data1.get(i).isChecked()); fuche.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //判断一级列表复选框的状态 设置为true或false data1.get(i).setChecked(fuche.isChecked()); //改变二级checkbod的状态 changeChildCbState(i,fuche.isChecked()); //算钱 EventBus.getDefault().post(computer()); //改变全选状态 isAllGroupCbSelect判断一级是否全部选中 changeAllCbState(isAllGroupCbSelect()); //必刷新 notifyDataSetChanged(); } }); return inflate; } @Override public View getChildView(final int i, final int i1, final boolean b, View view, ViewGroup viewGroup) { final Carbean.DataBean.ListBean listBean = data2.get(i).get(i1); final View inflate = View.inflate(context, R.layout.shopp_car_item, null); final View viewById = inflate.findViewById(R.id.btn_commodity_delete); final CheckBox ck_chose = inflate.findViewById(R.id.ck_chose); ImageView btn_commodity_delete = inflate.findViewById(R.id.btn_commodity_delete); if(flog){ btn_commodity_delete.setVisibility(View.VISIBLE); }else{ btn_commodity_delete.setVisibility(View.GONE); } btn_commodity_delete.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) {// int eduid = App.cxsp.getInt("eduid", 3515); Cardeletepersonlei cardeletepersonlei = new Cardeletepersonlei(new Deletecarinit() { @Override public void seecss(String bean) { List<Carbean.DataBean.ListBean> listBeen = data2.get(i); Carbean.DataBean.ListBean remove = listBeen.remove(i1); if (listBeen.size() == 0) { //先移除二级列表的集合,再移除一级列表的集合 data2.remove(i); data1.remove(i); notifyDataSetChanged(); } Toast.makeText(context,bean,Toast.LENGTH_SHORT).show(); } @Override public void faild(String shib) { Toast.makeText(context,shib,Toast.LENGTH_SHORT).show(); } }); cardeletepersonlei.edcanshu("http://120.27.23.105/product/deleteCart",3515+"",data2.get(i).get(i1).getPid()+""); } }); //中间的数量 final TextView tv_commodity_show_num = (TextView) inflate.findViewById(R.id.tv_commodity_show_num); //减去数量 TextView iv_sub = inflate.findViewById(R.id.iv_sub); //加上数量 TextView iv_add = inflate.findViewById(R.id.iv_add); //图片 ImageView iv_show_pic = inflate.findViewById(R.id.iv_show_pic); //名称 TextView tv_commodity_name = inflate.findViewById(R.id.tv_commodity_name); //价格 TextView tv_commodity_price = inflate.findViewById(R.id.tv_commodity_price); //介绍 TextView tv_commodity_attr = inflate.findViewById(R.id.tv_commodity_attr); String title = data2.get(i).get(i1).getTitle(); double price = data2.get(i).get(i1).getPrice(); String images = data2.get(i).get(i1).getImages(); String subhead = data2.get(i).get(i1).getSubhead(); int num = data2.get(i).get(i1).getNum(); String[] split = images.split("\\|"); Glide.with(context).load(split[1]).into(iv_show_pic); tv_commodity_name.setText(title); tv_commodity_price.setText(price+""); tv_commodity_attr.setText(subhead); tv_commodity_show_num.setText(num+""); //设置二级列表checkbox的属性 ck_chose.setChecked(data2.get(i).get(i1).isChecked()); //二级列表的点击事件 ck_chose.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //设置该条目中的checkbox属性值 listBean.setChecked(ck_chose.isChecked()); //计算价钱 PriceAndCountEvent priceAndCountEvent = computer(); EventBus.getDefault().post(priceAndCountEvent); //判断当前checkbox是选中的状态 if (ck_chose.isChecked()) { //如果全部选中(isAllChildCbSelected) if (isAllChildCbSelected(i)) { //改变一级列表的状态 changeGroupCbState(i, true); //改变全选的状态 changeAllCbState(isAllGroupCbSelect()); } } else { //如果没有全部选中,一级列表的checkbox为false不为选中 changeGroupCbState(i, false); changeAllCbState(isAllGroupCbSelect()); } notifyDataSetChanged(); } }); //加号 iv_add.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { int num = listBean.getNum(); //num为int类型所以要加空字符串 tv_commodity_show_num.setText(++num+""); listBean.setNum(num); //如果二级列表的checkbox为选中,计算价钱 if (ck_chose.isChecked()) { PriceAndCountEvent priceAndCountEvent = computer(); EventBus.getDefault().post(priceAndCountEvent); } } }); //减号 iv_sub.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { int num = listBean.getNum(); if (num == 1) { return; } tv_commodity_show_num.setText(--num + ""); listBean.setNum(num); if (ck_chose.isChecked()) { PriceAndCountEvent priceAndCountEvent = computer(); EventBus.getDefault().post(priceAndCountEvent); } } }); return inflate; } @Override public boolean isChildSelectable(int i, int i1) { return false; } //下面完事 //改变二级列表的checkbox的状态 如果一级选中,控制二级也选中 private void changeChildCbState(int groupPosition, boolean flag) { List<Carbean.DataBean.ListBean> listBeen = data2.get(groupPosition); for (int j = 0; j < listBeen.size(); j++) { Carbean.DataBean.ListBean listBean = listBeen.get(j); listBean.setChecked(flag); } } //判断一级列表是否全部选中 public boolean isAllGroupCbSelect() { for (int i = 0; i < data2.size(); i++) { Carbean.DataBean dataBean = data1.get(i); if (!dataBean.isChecked()) { return false; } } return true; } //改变全选的状态 private void changeAllCbState(boolean flag) { MessageEvent messageEvent = new MessageEvent(); messageEvent.setCheckd(flag); EventBus.getDefault().post(messageEvent); } //改变一级列表的checkbox的状态 private void changeGroupCbState(int i, boolean flag) { Carbean.DataBean dataBean = data1.get(i); dataBean.setChecked(flag); } //判断二级列表是否全部选中 private boolean isAllChildCbSelected(int i) { List<Carbean.DataBean.ListBean> listBeen = data2.get(i); for (int j = 0; j < listBeen.size(); j++) { Carbean.DataBean.ListBean listBean = listBeen.get(j); if (!listBean.isChecked()) { return false; } } return true; } //设置全选,反选 public void changeAllListCbState(boolean flag) { for (int i = 0; i < data2.size(); i++) { changeGroupCbState(i, flag); changeChildCbState(i, flag); } //算钱 EventBus.getDefault().post(computer()); notifyDataSetChanged(); } private PriceAndCountEvent computer() { int count = 0; int price = 0; int to = 0; for (int i = 0; i < data2.size(); i++) { List<Carbean.DataBean.ListBean> listBeen = data2.get(i); for (int j = 0; j < listBeen.size(); j++) { Carbean.DataBean.ListBean listBean = listBeen.get(j); if (listBean.isChecked()) { price += listBean.getNum() * listBean.getPrice(); count += listBean.getNum(); to += listBean.getNum(); } } } PriceAndCountEvent priceAndCountEvent = new PriceAndCountEvent(); priceAndCountEvent.setCount(count); priceAndCountEvent.setPrice(price); priceAndCountEvent.setTo(to); return priceAndCountEvent; }}
// MessageEvent 购物车计算价钱的类
public class MessageEvent { private boolean checkd; public boolean isCheckd(){ return checkd; } public void setCheckd(boolean checkd){ this.checkd=checkd; }}
//PriceAndCountEvent
package com.example.gwc.sylei;/** * Created by HASEE on 2017/11/22. */public class PriceAndCountEvent { private int price; private int count; private int to; public int getPrice() { return price; } public int getCount() { return count; } public int getTo(){ return to; } public void setPrice(int price) { this.price = price; } public void setCount(int count) { this.count = count; } public void setTo(int to) { this.to = to; }}
// Carfubean bean里面的分两个集合的泛型
package com.example.gwc.Myshopingcar;public class Carfubean { private String shopName; private boolean isFatherflag; public Carfubean(String shopName, boolean isFatherflag) { this.shopName = shopName; this.isFatherflag = isFatherflag; } public String getShopName() { return shopName; } public void setShopName(String shopName) { this.shopName = shopName; } public boolean isFatherflag() { return isFatherflag; } public void setFatherflag(boolean fatherflag) { isFatherflag = fatherflag; }}//Carsonbean
package com.example.gwc.Myshopingcar;// "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.0,// "pscid": 1,// "selected": 0,// "sellerid": 17,// "subhead": "每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下",// "title": "北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"public class Carsonbean { private String createtime; private String images; private int num; private int pid; private double price; private String subhead; private String title; private boolean isChildFlag; public Carsonbean(String createtime, String images, int num, int pid, double price, String subhead, String title, boolean isChildFlag) { this.createtime = createtime; this.images = images; this.num = num; this.pid = pid; this.price = price; this.subhead = subhead; this.title = title; this.isChildFlag = isChildFlag; } public String getCreatetime() { return createtime; } public void setCreatetime(String createtime) { this.createtime = createtime; } 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 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; } public boolean isChildFlag() { return isChildFlag; } public void setChildFlag(boolean childFlag) { isChildFlag = childFlag; }}
package com.example.gwc.Myshopingcar;import java.util.List;public class Carbean { /** * msg : 请求成功 * code : 0 * data : [{"list":[{"bargainPrice":11800,"createtime":"2017-10-14T21:48:08","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":60,"price":13888,"pscid":40,"selected":0,"sellerid":4,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"},{"bargainPrice":3455,"createtime":"2017-10-14T21:38:26","detailUrl":"https://item.m.jd.com/product/12224420750.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t9106/106/1785172479/537280/253bc0ab/59bf78a7N057e5ff7.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t9106/106/1785172479/537280/253bc0ab/59bf78a7N057e5ff7.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8461/5/1492479653/68388/7255e013/59ba5e84N91091843.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8461/5/1492479653/68388/7255e013/59ba5e84N91091843.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8803/356/1478945529/489755/2a163ace/59ba5e84N7bb9a666.jpg!q70.jpg","num":1,"pid":48,"price":222,"pscid":39,"selected":0,"sellerid":4,"subhead":"【现货新品抢购】全面屏2.0震撼来袭,骁龙835处理器,四曲面陶瓷机","title":"小米(MI) 小米MIX2 手机 黑色 全网通 (6GB+64GB)【标配版】"}],"sellerName":"商家4","sellerid":"4"}] */ private String msg; private String code; private List<DataBean> data; public Carbean(String msg, String code, List<DataBean> data) { this.msg = msg; this.code = code; this.data = data; } @Override public String toString() { return "Carbean{" + "msg='" + msg + '\'' + ", code='" + code + '\'' + ", data=" + 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 { public boolean isChecked() { return checked; } public void setChecked(boolean checked) { this.checked = checked; } /** * list : [{"bargainPrice":11800,"createtime":"2017-10-14T21:48:08","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":60,"price":13888,"pscid":40,"selected":0,"sellerid":4,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"},{"bargainPrice":3455,"createtime":"2017-10-14T21:38:26","detailUrl":"https://item.m.jd.com/product/12224420750.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t9106/106/1785172479/537280/253bc0ab/59bf78a7N057e5ff7.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t9106/106/1785172479/537280/253bc0ab/59bf78a7N057e5ff7.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8461/5/1492479653/68388/7255e013/59ba5e84N91091843.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8461/5/1492479653/68388/7255e013/59ba5e84N91091843.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8803/356/1478945529/489755/2a163ace/59ba5e84N7bb9a666.jpg!q70.jpg","num":1,"pid":48,"price":222,"pscid":39,"selected":0,"sellerid":4,"subhead":"【现货新品抢购】全面屏2.0震撼来袭,骁龙835处理器,四曲面陶瓷机","title":"小米(MI) 小米MIX2 手机 黑色 全网通 (6GB+64GB)【标配版】"}] * sellerName : 商家4 * sellerid : 4 */ private boolean checked; private String sellerName; private String sellerid; private List<ListBean> list; public DataBean(String sellerName, String sellerid, List<ListBean> list) { this.sellerName = sellerName; this.sellerid = sellerid; this.list = list; } @Override public String toString() { return "DataBean{" + "sellerName='" + sellerName + '\'' + ", sellerid='" + sellerid + '\'' + ", list=" + 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 { public boolean isChecked() { return checked; } public void setChecked(boolean checked) { this.checked = checked; } /** * bargainPrice : 11800.0 * createtime : 2017-10-14T21:48:08 * 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 : 60 * price : 13888.0 * pscid : 40 * selected : 0 * sellerid : 4 * subhead : 购买电脑办公部分商品满1元返火车票5元优惠券(返完即止) * title : 全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G */ 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; @Override public String toString() { return "ListBean{" + "bargainPrice=" + bargainPrice + ", createtime='" + createtime + '\'' + ", detailUrl='" + detailUrl + '\'' + ", images='" + images + '\'' + ", num=" + num + ", pid=" + pid + ", price=" + price + ", pscid=" + pscid + ", selected=" + selected + ", sellerid=" + sellerid + ", subhead='" + subhead + '\'' + ", title='" + title + '\'' + '}'; } public ListBean(double bargainPrice, String createtime, String detailUrl, String images, int num, int pid, double price, int pscid, int selected, int sellerid, String subhead, String title) { this.bargainPrice = bargainPrice; this.createtime = createtime; this.detailUrl = detailUrl; this.images = images; this.num = num; this.pid = pid; this.price = price; this.pscid = pscid; this.selected = selected; this.sellerid = sellerid; this.subhead = subhead; this.title = 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; } } }}
//Myshopingcar的mvp
//Carinit
public interface Carinit { void seecss(Carbean bean); void faild(String shib);}
//Carperson
public interface Carperson { void edcanshu(String path);}//Carpersonlei
public class Carpersonlei implements Carperson,Carmodel.Onfinsh{ private Carinit carinit; private final Carmodellei carmodellei; public Carpersonlei(Carinit carinit) { this.carinit = carinit; carmodellei = new Carmodellei(); } @Override public void edcanshu(String path) { if(carinit==null){ return; } carmodellei.edcanshu(path,this); } @Override public void Success(Carbean cg) { carinit.seecss(cg); } @Override public void Failed(String sc) { carinit.faild(sc); }}
//Carmodel
public interface Carmodel { public interface Onfinsh { void Success(Carbean cg); void Failed(String sc);} void edcanshu(String path, Onfinsh onfinsh);}
//Carmodellei
public class Carmodellei implements Carmodel { @Override public void edcanshu(String path, final Onfinsh onfinsh) { Edokthhp.getInert().doGet(path, new Okinteface() { @Override public void chenggong(String cheng) { Gson gson = new Gson(); Carbean carbean = gson.fromJson(cheng, Carbean.class); onfinsh.Success(carbean); } @Override public void shibai(String shi) { onfinsh.Failed(shi); } }); }}
//Okinteface
public interface Okinteface { void chenggong(String cheng); void shibai(String shi); }
//两个ok注意大小写 Edokthhp
public class Edokthhp { private Handler handler=new Handler(); private static Edokthhp okHttp; private Edokthhp(){ } public static Edokthhp getInert(){ if(null == okHttp){ synchronized (Edokthhp.class){ okHttp=new Edokthhp(); } } return okHttp; } public void doGet(String path,final Okinteface okinteface){ OkHttpClient okHttpClient = new OkHttpClient(); final Request request = new Request.Builder() .get() .url(path) .build(); Call call = okHttpClient.newCall(request); call.enqueue(new Callback() { private String string; @Override public void onFailure(Call call, final IOException e) { handler.post(new Runnable() { @Override public void run() { okinteface.shibai(e.getMessage()); } }); } @Override public void onResponse(Call call, final Response response) throws IOException { string = response.body().string(); handler.post(new Runnable() { @Override public void run() { okinteface.chenggong(string); } }); } }); }}
//EdOkthhp
public class EdOkthhp { private Handler handler=new Handler(); private static EdOkthhp okHttp; private EdOkthhp(){ } public static EdOkthhp getInert(){ if(null == okHttp){ synchronized (EdOkthhp.class){ okHttp=new EdOkthhp(); } } return okHttp; } public void doGet(String path, Map<String,String> map, final Okinteface okinteface){ StringBuffer sb=null; for(String key:map.keySet()){ if(sb==null){ sb=new StringBuffer(); sb.append("?"); }else{ sb.append("&"); } sb.append(key).append("=").append(map.get(key)); } OkHttpClient okHttpClient = new OkHttpClient(); final Request request = new Request.Builder() .get() .url(path+sb.toString()) .build(); Log.e("arr",path+sb.toString()); Call call = okHttpClient.newCall(request); call.enqueue(new Callback() { @Override public void onFailure(Call call, final IOException e) { handler.post(new Runnable() { @Override public void run() { okinteface.shibai(e.getMessage()); } }); } @Override public void onResponse(Call call, final Response response) throws IOException { final String string = response.body().string(); handler.post(new Runnable() { @Override public void run() { okinteface.chenggong(string); } }); } }); }}
//依赖
compile 'com.android.support:design:26.0.0-alpha1' compile 'com.hjm:BottomTabBar:1.1.1' compile 'com.squareup.okhttp3:okhttp:3.4.1' compile 'com.android.support:recyclerview-v7:26.+' compile 'com.jcodecraeer:xrecyclerview:1.2.0' compile 'q.rorbin:VerticalTabLayout:1.2.5' compile 'com.google.code.gson:gson:2.2.4' compile 'org.greenrobot:eventbus:3.1.1' compile 'com.android.support:appcompat-v7:26.+' compile 'com.android.support.constraint:constraint-layout:1.0.2' compile 'com.github.bumptech.glide:glide:3.7.0'
阅读全文
0 0
- android_购物车
- Android_添加购物车
- Android_查询购物车
- Android_删除购物车
- Android_二级列表购物车逻辑
- Android_购物车实现输入加减功能
- android_购物车增删改查,结算,全选全不选
- Android_二级列表购物车之增删改查,全选反选,加减器,价钱数量计算
- Android_二级列表购物车之增删改查,全选反选,加减器,价钱数量计算
- android_购物车三种状态之拦截器 post请求
- 购物车
- 购物车
- 购物车
- 购物车
- 购物车
- 购物车
- 购物车
- 购物车
- poj1149 PIGS(建图最大流)
- windows7设置定时任务运行ThinkPHP框架程序
- python 剑指offer 面试题37
- 准备数据结构项目
- SPark算子学习之FlatMap和Glom和randomSplit
- android_购物车
- ListBox实现上移,下移,左移,右移操作
- 2017/12/20
- SpringBoot中使用AOP 监控sql耗时
- 关于bin/storm nimbus >/dev/null 2>&1 &
- windows10上使用apache部署python flask webapp
- TensorFlow的MNIST数据识别
- 结构体学习1
- 无头单链表