购物车

  1. //依赖  
  2.    compile 'io.reactivex.rxjava2:rxjava:2.0.1'  //Rxjava  
  3.    compile 'io.reactivex.rxjava2:rxandroid:2.0.1'  //Rx安卓  
  4.    compile 'com.squareup.retrofit2:retrofit:2.3.0' //Retrofit请求网络  
  5.    compile 'com.squareup.retrofit2:converter-gson:2.3.0'//Gson  
  6.    compile 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'  
  7.    compile 'com.squareup.okhttp3:logging-interceptor:3.5.0'//拦截器  
  8.    compile 'com.youth.banner:banner:1.4.9' //Banner依赖  
  9.    //图片的依赖  
  10.    compile 'com.facebook.fresco:fresco:0.14.1'  
  11.    compile 'com.facebook.fresco:animated-base-support:0.14.1'  
  12.    compile 'com.facebook.fresco:animated-gif:0.14.1'  
  13.    compile 'com.facebook.fresco:webpsupport:0.14.1'  
  14.    compile 'com.facebook.fresco:animated-webp:0.14.1'  
  15.    compile 'com.facebook.fresco:imagepipeline-okhttp3:0.14.1'  

[html]  view plain  copy
  1. //网络状态  
  2.    <uses-permission android:name="android.permission.INTERNET" />  
  3.    //sd读写权限  
  4.    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />  
  5.    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />  
  6.   
  7.  android:name=".MApp"  

[html]  view plain  copy
  1. 封装Activity  
  2. /**  
  3.  * Description:基类,封装功用功能,方便子类继承,子类只需要实现子类需要的功能即可  
  4.  */  
  5. public abstract class BaseActivity extends AppCompatActivity{  
  6.   
  7.     private boolean isStatus = false;//沉浸式透明状态栏标示  
  8.     private boolean isShowActionBar = true;//是否隐藏actionbar  
  9.     private boolean isFullScreen = false;  
  10.   
  11.   
  12.     @Override  
  13.     protected void onCreate(@Nullable Bundle savedInstanceState) {  
  14.         super.onCreate(savedInstanceState);  
  15.   
  16.         setContentView(bindLayout());  
  17.         initView();  
  18.         initData();  
  19.         setListener();  
  20.     }  
  21.   
  22.     protected abstract int bindLayout();//绑定布局  
  23.   
  24.     protected abstract void initView();//初始化控件  
  25.   
  26.     protected abstract void initData();//初始化数据  
  27.   
  28.     protected abstract void setListener();//初始化点击事件  
  29.   
  30.   
  31.     /**  
  32.      * 跳转activity方法  
  33.      * @param clazz  
  34.      */  
  35.     public void startActivity(Class> clazz) {  
  36.         Intent intent = new Intent(this, clazz);  
  37.         startActivity(intent);  
  38.     }  
  39.     /**  
  40.      * 跳转activity方法,带参数  
  41.      * @param clazz  
  42.      */  
  43.     public void startActivity(Bundle bundle,Class> clazz) {  
  44.         Intent intent = new Intent(this, clazz);  
  45.         intent.putExtras(bundle);  
  46.         startActivity(intent);  
  47.     }  
  48.   
  49.     public void setStatus(boolean status) {  
  50.         isStatus = status;  
  51.         if (isStatus){  
  52.             //判断当前设备的版本号》=19的时候,走这个代码块,这个用于版本适配  
  53.             if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.KITKAT){  
  54.   
  55.                 getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);  
  56.             }  
  57.         }  
  58.     }  
  59.   
  60.     public void setShowActionBar(boolean showActionBar) {  
  61.         isShowActionBar = showActionBar;  
  62.   
  63.         if (isShowActionBar){  
  64.             getSupportActionBar().show();  
  65.         }else{  
  66.             getSupportActionBar().hide();  
  67.         }  
  68.     }  
  69.   
  70.     public void setFullScreen(boolean fullScreen) {  
  71.         isFullScreen = fullScreen;  
  72.         if (isFullScreen){//是全屏的时候  
  73.             getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);  
  74.         }  
  75.     }  
  76.   
  77.     public void showToast(String msg){  
  78.         Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();  
  79.     }  
  80. }  
[html]  view plain  copy
  1. //Bean类  
  2. //显示购物车数据  
  3. public class CartBean {  
  4.   
  5.     private String code;  
  6.     private String msg;  
  7.     private List<DataBean> data;  
  8.   
  9.     public String getCode() {  
  10.         return code;  
  11.     }  
  12.   
  13.     public void setCode(String code) {  
  14.         this.code = code;  
  15.     }  
  16.   
  17.     public String getMsg() {  
  18.         return msg;  
  19.     }  
  20.   
  21.     public void setMsg(String msg) {  
  22.         this.msg = msg;  
  23.     }  
  24.   
  25.     public List<DataBean> getData() {  
  26.         return data;  
  27.     }  
  28.   
  29.     public void setData(List<DataBean> data) {  
  30.         this.data = data;  
  31.     }  
  32.   
  33.     public static class DataBean {  
  34.          
  35.         private String sellerName;  
  36.         private String sellerid;  
  37.         private List<ListBean> list;  
  38.         private boolean check;  
  39.   
  40.         public boolean isCheck() {  
  41.             return check;  
  42.         }  
  43.   
  44.         public void setCheck(boolean check) {  
  45.             this.check = check;  
  46.         }  
  47.         public String getSellerName() {  
  48.             return sellerName;  
  49.         }  
  50.   
  51.         public void setSellerName(String sellerName) {  
  52.             this.sellerName = sellerName;  
  53.         }  
  54.   
  55.         public String getSellerid() {  
  56.             return sellerid;  
  57.         }  
  58.   
  59.         public void setSellerid(String sellerid) {  
  60.             this.sellerid = sellerid;  
  61.         }  
  62.   
  63.         public List<ListBean> getList() {  
  64.             return list;  
  65.         }  
  66.   
  67.         public void setList(List<ListBean> list) {  
  68.             this.list = list;  
  69.         }  
  70.   
  71.         public static class ListBean {  
  72.             
  73.             private double bargainPrice;  
  74.             private String createtime;  
  75.             private String detailUrl;  
  76.             private String images;  
  77.             private int num;  
  78.             private int pid;  
  79.             private double price;  
  80.             private int pscid;  
  81.             private int selected;  
  82.             private int sellerid;  
  83.             private String subhead;  
  84.             private String title;  
  85.             private boolean check;  
  86.   
  87.   
  88.             public boolean isCheck() {  
  89.                 return check;  
  90.             }  
  91.   
  92.             public void setCheck(boolean check) {  
  93.                 this.check = check;  
  94.             }  
  95.             public double getBargainPrice() {  
  96.                 return bargainPrice;  
  97.             }  
  98.   
  99.             public void setBargainPrice(double bargainPrice) {  
  100.                 this.bargainPrice = bargainPrice;  
  101.             }  
  102.   
  103.             public String getCreatetime() {  
  104.                 return createtime;  
  105.             }  
  106.   
  107.             public void setCreatetime(String createtime) {  
  108.                 this.createtime = createtime;  
  109.             }  
  110.   
  111.             public String getDetailUrl() {  
  112.                 return detailUrl;  
  113.             }  
  114.   
  115.             public void setDetailUrl(String detailUrl) {  
  116.                 this.detailUrl = detailUrl;  
  117.             }  
  118.   
  119.             public String getImages() {  
  120.                 return images;  
  121.             }  
  122.   
  123.             public void setImages(String images) {  
  124.                 this.images = images;  
  125.             }  
  126.   
  127.             public int getNum() {  
  128.                 return num;  
  129.             }  
  130.   
  131.             public void setNum(int num) {  
  132.                 this.num = num;  
  133.             }  
  134.   
  135.             public int getPid() {  
  136.                 return pid;  
  137.             }  
  138.   
  139.             public void setPid(int pid) {  
  140.                 this.pid = pid;  
  141.             }  
  142.   
  143.             public double getPrice() {  
  144.                 return price;  
  145.             }  
  146.   
  147.             public void setPrice(double price) {  
  148.                 this.price = price;  
  149.             }  
  150.   
  151.             public int getPscid() {  
  152.                 return pscid;  
  153.             }  
  154.   
  155.             public void setPscid(int pscid) {  
  156.                 this.pscid = pscid;  
  157.             }  
  158.   
  159.             public int getSelected() {  
  160.                 return selected;  
  161.             }  
  162.   
  163.             public void setSelected(int selected) {  
  164.                 this.selected = selected;  
  165.             }  
  166.   
  167.             public int getSellerid() {  
  168.                 return sellerid;  
  169.             }  
  170.   
  171.             public void setSellerid(int sellerid) {  
  172.                 this.sellerid = sellerid;  
  173.             }  
  174.   
  175.             public String getSubhead() {  
  176.                 return subhead;  
  177.             }  
  178.   
  179.             public void setSubhead(String subhead) {  
  180.                 this.subhead = subhead;  
  181.             }  
  182.   
  183.             public String getTitle() {  
  184.                 return title;  
  185.             }  
  186.   
  187.             public void setTitle(String title) {  
  188.                 this.title = title;  
  189.             }  
  190.         }  
  191.     }  
  192. }  
  193.   
  194. //-------------购物车删改的类  
  195. public class AddCartBean {  
  196.     /**  
  197.      * msg : 加购成功  
  198.      * code : 0  
  199.      */  
  200.     private String msg;  
  201.     private String code;  
  202.   
  203.     public String getMsg() {  
  204.         return msg;  
  205.     }  
  206.   
  207.     public void setMsg(String msg) {  
  208.         this.msg = msg;  
  209.     }  
  210.   
  211.     public String getCode() {  
  212.         return code;  
  213.     }  
  214.   
  215.     public void setCode(String code) {  
  216.         this.code = code;  
  217.     }  
  218. }  

[html]  view plain  copy
  1. //utils  
  2. //根目录  
  3. public class HttpConfig {  
  4.     //retrofit根目录  
  5.     public static final String _URL="http://120.27.23.105/";  
  6. }  
  7. //--------------计算价格的类  
  8. public class JisuanUtils {  
  9.     /**  
  10.      * 提供精确的加法运算。  
  11.      * @param v1 被加数  
  12.      * @param v2 加数  
  13.      * @return 两个参数的和  
  14.      */  
  15.     public static double add(double v1,double v2){  
  16.         BigDecimal b1 = new BigDecimal(Double.toString(v1));  
  17.         BigDecimal b2 = new BigDecimal(Double.toString(v2));  
  18.         return b1.add(b2).doubleValue();  
  19.     }  
  20.     /**  
  21.      * 提供精确的减法运算。  
  22.      * @param v1 被减数  
  23.      * @param v2 减数  
  24.      * @return 两个参数的差  
  25.      */  
  26.     public static double sub(double v1,double v2){  
  27.         BigDecimal b1 = new BigDecimal(Double.toString(v1));  
  28.         BigDecimal b2 = new BigDecimal(Double.toString(v2));  
  29.         return b1.subtract(b2).doubleValue();  
  30.     }  
  31.     /**  
  32.      * 提供精确的乘法运算。  
  33.      * @param v1 被乘数  
  34.      * @param v2 乘数  
  35.      * @return 两个参数的积  
  36.      */  
  37.     public static double mul(double v1,double v2){  
  38.         BigDecimal b1 = new BigDecimal(Double.toString(v1));  
  39.         BigDecimal b2 = new BigDecimal(Double.toString(v2));  
  40.         return b1.multiply(b2).doubleValue();  
  41.     }  
  42.   
  43. }  
  44.   
  45. //-----------------------网络请求类  
  46. /**  
  47.  * Description:retrofit工具类  
  48.  * 构造者模式如何封装:首先有各种builder过程,最后通过build()方法对对象进行创建  
  49.  */  
  50. public class RetrofitUtils {  
  51.   
  52.     //创建私有属性  
  53.     private static RetrofitUtils mInstance;  
  54.     //创建ApiService引用  
  55.     private static ApiService apiService;  
  56.   
  57.     /**  
  58.      * 声明私有构造方法,类似于单利模式,让调用者无法new出对象,只能通过构造者模式创建对象  
  59.      */  
  60.     private RetrofitUtils() {  
  61.   
  62.     }  
  63.   
  64.     /**  
  65.      * 先后调用的过程,只有对象给build成功之后,才能调用apiservice,这也是retrofit的几个先后的步骤  
  66.      * @return  
  67.      */  
  68.     public ApiService getApiService() {  
  69.         return apiService;  
  70.     }  
  71.   
  72.     public static class Builder {  
  73.   
  74.         private OkHttpClient okHttpClient;  
  75.   
  76.         private List<CallAdapter.Factory> callAdapterFactorys = new ArrayList<>();  
  77.         private List<Converter.Factory> convertFactorys = new ArrayList<>();  
  78.   
  79.         public Builder addCallAdapterFactory(CallAdapter.Factory factory) {  
  80.             callAdapterFactorys.add(factory);  
  81.             return this;//返回this的目的是:可以链式调用  
  82.         }  
  83.   
  84.         public Builder addConverterFactory(Converter.Factory factory) {  
  85.             convertFactorys.add(factory);  
  86.             return this;  
  87.         }  
  88.   
  89.         public Builder client(OkHttpClient okHttpClient) {  
  90.             this.okHttpClient = okHttpClient;  
  91.             return this;  
  92.         }  
  93.   
  94.         /**  
  95.          * build方法才是真正的业务逻辑操作,才是真正构建对象的过程  
  96.          * @return  
  97.          */  
  98.         public RetrofitUtils build() {  
  99.   
  100.   
  101.             Retrofit.Builder builder = new Retrofit.Builder();  
  102.   
  103.             if (convertFactorys != null && convertFactorys.size() == 0) {  
  104.                 //如果集合中没有对象,我们添加默认的gson解析器  
  105.                 builder.addConverterFactory(GsonConverterFactory.create());  
  106.             }  
  107.   
  108.             for (Converter.Factory convertFactory : convertFactorys) {  
  109.                 builder.addConverterFactory(convertFactory);  
  110.             }  
  111.   
  112.             if (callAdapterFactorys != null && callAdapterFactorys.size() == 0) {  
  113.                 builder.addCallAdapterFactory(RxJava2CallAdapterFactory.create());  
  114.   
  115.             }  
  116.   
  117.             for (CallAdapter.Factory callAdapterFactory : callAdapterFactorys) {  
  118.                 builder.addCallAdapterFactory(callAdapterFactory);  
  119.             }  
  120.   
  121.             //第一步创建retrofit对象  
  122.             Retrofit retrofit = builder.client(okHttpClient).baseUrl(HttpConfig._URL)  
  123.                     .build();  
  124.             //第二步,创建apiservice接口类  
  125.             apiService = retrofit.create(ApiService.class);  
  126.             //第三步,请求逻辑(这个供外部调用者调用)  
  127.             mInstance = new RetrofitUtils();//私有构造方法,只有本类可以new出实例  
  128.             return mInstance;  
  129.         }  
  130.     }  
  131. }  

[html]  view plain  copy
  1. //ApiService网络请求接口  
  2. public interface ApiService {  
  3.     @GET("product/getCarts?source=android")  
  4.     Observable<CartBean> rxjavaShowCart(@Query("uid") String uid);  
  5.   
  6.     @POST("product/deleteCart")  
  7.     @FormUrlEncoded  
  8.     Observable<AddCartBean> rxjavaDeleteCart(@FieldMap Map<String, String> map);  
  9.   
  10.     @POST("product/updateCarts")  
  11.     @FormUrlEncoded  
  12.     Observable<AddCartBean> rxjavaUpdateCarts(@FieldMap Map<String, String> map);  
  13. }  

[html]  view plain  copy
  1.   
[html]  view plain  copy
  1. //model层  
  2. //--------删除  
  3. public class DeleteCartModel {  
  4.     public void deleteCart(String uid,String pid,final DeleteCartCallback deleteCartCallback){  
  5.         Map<String, String> map = new HashMap<>();  
  6.         map.put("uid", uid);  
  7.         map.put("pid", pid);  
  8.         OkHttpClient okHttpClient = new OkHttpClient.Builder()  
  9.                 .addNetworkInterceptor(new HttpLoggingInterceptor()  
  10.                         .setLevel(HttpLoggingInterceptor.Level.BODY))  
  11.                 .build();  
  12.         Retrofit retrofit = new Retrofit.Builder()  
  13.                 .client(okHttpClient)  
  14.                 .addConverterFactory(GsonConverterFactory.create())  
  15.                 .addCallAdapterFactory(RxJava2CallAdapterFactory.create())  
  16.                 .baseUrl(HttpConfig._URL).build();  
  17.         ApiService apiService = retrofit.create(ApiService.class);  
  18.         apiService.rxjavaDeleteCart(map).subscribeOn(Schedulers.io())  
  19.                 .observeOn(AndroidSchedulers.mainThread())  
  20.                 .subscribe(new Observer<AddCartBean>() {  
  21.                     @Override  
  22.                     public void onSubscribe(Disposable d) {  
  23.   
  24.                     }  
  25.   
  26.                     @Override  
  27.                     public void onNext(AddCartBean value) {  
  28.                         if (value.getCode().equals("0")) {  
  29.                             deleteCartCallback.deleteCartSuccess(value);  
  30.                         }  
  31.                     }  
  32.   
  33.                     @Override  
  34.                     public void onError(Throwable e) {  
  35.                         deleteCartCallback.failure(e);  
  36.                     }  
  37.   
  38.                     @Override  
  39.                     public void onComplete() {  
  40.   
  41.                     }  
  42.                 });  
  43.   
  44.   
  45.     }  
  46.     public interface DeleteCartCallback {  
  47.         void deleteCartSuccess(AddCartBean bean);//网络请求成功  
  48.         void failure(Throwable t);//网络请求失败  
  49.     }  
  50. }  


[html]  view plain  copy
  1. //presenter层  
  2. public class ShowCartPresenter {  
  3.     private final IShowCartView view;  
  4.     private final ShowCartModel showCartModel;  
  5.     private final DeleteCartModel deleteCartModel;  
  6.     private final UpdateCartsModel updateCartsModel;  
  7.   
  8.     public ShowCartPresenter(IShowCartView iShowCartView) {  
  9.         showCartModel = new ShowCartModel();  
  10.         deleteCartModel = new DeleteCartModel();  
  11.         updateCartsModel = new UpdateCartsModel();  
  12.         this.view=iShowCartView;  
  13.     }  
  14.     public void showCart(String uid) {  
  15.         showCartModel.showCart(uid, new ShowCartModel.ShowCartCallback() {  
  16.             @Override  
  17.             public void showCartSuccess(CartBean bean) {  
  18.                 List<CartBean.DataBean> data = bean.getData();  
  19.                 view.showCartSuccess(data);  
  20.             }  
  21.   
  22.             @Override  
  23.             public void failure(Throwable t) {  
  24.                 view.showCartfailure(t);  
  25.             }  
  26.         });  
  27.     }  
  28.   
  29.     public void deleteCart(String uid,String pid){  
  30.         deleteCartModel.deleteCart(uid, pid, new DeleteCartModel.DeleteCartCallback() {  
  31.             @Override  
  32.             public void deleteCartSuccess(AddCartBean bean) {  
  33.                 view.deleteCartSuccess(bean.getMsg());  
  34.             }  
  35.   
  36.             @Override  
  37.             public void failure(Throwable t) {  
  38.                 view.deleteCartfailure(t);  
  39.             }  
  40.         });  
  41.     }  
  42.     public void updateCarts(String uid,String sellerid,String pid,String selected,String num){  
  43.         updateCartsModel.updateCarts(uid, sellerid, pid, selected, num, new UpdateCartsModel.UpdateCartsCallback() {  
  44.             @Override  
  45.             public void updateCartsSuccess(AddCartBean bean) {  
  46.                 view.updateCartsSuccess(bean.getMsg());  
  47.             }  
  48.   
  49.             @Override  
  50.             public void failure(Throwable t) {  
  51.                 view.updateCartsfailure(t);  
  52.             }  
  53.         });  
  54.     }  
  55. }  

[html]  view plain  copy
  1. //view层  
  2. public interface IShowCartView {  
  3.     void showCartSuccess(List<CartBean.DataBean> data);//网络请求成功  
  4.     void showCartfailure(Throwable t);//网络请求失败(断网,服务器崩溃,接口地址不正确,弱网)  
  5.     void jisuan(String count,String priceAll);  
  6.     void deleteCartSuccess(String str);//网络请求成功  
  7.     void deleteCartfailure(Throwable t);//网络请求失败(断网,服务器崩溃,接口地址不正确,弱网)  
  8.     void updateCartsSuccess(String str);//网络请求成功  
  9.     void updateCartsfailure(Throwable t);//网络请求失败(断网,服务器崩溃,接口地址不正确,弱网)  
  10. }  

[html]  view plain  copy
  1. //自定义加减器  
  2. public class AddMinusView extends LinearLayout {  
  3.   
  4.     private OnAddMinusClickListener listener;  
  5.     private EditText etNumber;  
  6.   
  7.     //对外提供一个点击的回调接口  
  8.     public interface OnAddMinusClickListener{  
  9.         void onAddClick(View v);  
  10.         void onMinusClick(View v);  
  11.         void onEtNumberClick(View v);  
  12.     }  
  13.   
  14.     public void setOnAddMinusClickListener(OnAddMinusClickListener listener){  
  15.         if(listener!=null){  
  16.             this.listener=listener;  
  17.         }  
  18.     }  
  19.     public AddMinusView(Context context) {  
  20.         this(context,null);  
  21.     }  
  22.   
  23.     public AddMinusView(Context context, @Nullable AttributeSet attrs) {  
  24.         this(context, attrs,0);  
  25.     }  
  26.   
  27.     public AddMinusView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {  
  28.         super(context, attrs, defStyleAttr);  
  29.         initView(context, attrs, defStyleAttr);  
  30.     }  
  31.   
  32.     private void initView(Context context, AttributeSet attrs, int defStyleAttr) {  
  33.         View.inflate(context, R.layout.layout_add_minus,this);  
  34.   
  35.         //获取控件  
  36.         TextView txtminus=findViewById(R.id.txt_minus);  
  37.         TextView txtAdd=findViewById(R.id.txt_add);  
  38.         etNumber = findViewById(R.id.et_number);  
  39.   
  40.   
  41.         TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.AddMinusViewStyle);  
  42.   
  43.         String leftText = typedArray.getString(R.styleable.AddMinusViewStyle_left_text);  
  44.         String rightText = typedArray.getString(R.styleable.AddMinusViewStyle_right_text);  
  45.         String middleText = typedArray.getString(R.styleable.AddMinusViewStyle_middle_text);  
  46.         int color = typedArray.getColor(R.styleable.AddMinusViewStyle_left_text_color, Color.RED);  
  47.   
  48.         txtminus.setText(leftText);  
  49.         txtAdd.setText(rightText);  
  50.         etNumber.setText(middleText);  
  51.         txtminus.setTextColor(color);  
  52.   
  53.         //回收  
  54.         typedArray.recycle();  
  55.   
  56.   
  57.         txtminus.setOnClickListener(new OnClickListener() {  
  58.             @Override  
  59.             public void onClick(View view) {  
  60.                 listener.onMinusClick(view);  
  61.             }  
  62.         });  
  63.   
  64.         txtAdd.setOnClickListener(new OnClickListener() {  
  65.             @Override  
  66.             public void onClick(View view) {  
  67.                 listener.onAddClick(view);  
  68.             }  
  69.         });  
  70.         etNumber.setOnClickListener(new OnClickListener() {  
  71.             @Override  
  72.             public void onClick(View view) {  
  73.                 listener.onEtNumberClick(view);  
  74.             }  
  75.         });  
  76.   
  77.     }  
  78.     //对外提供一个修改数字的方法  
  79.     public void setNumber(int number){  
  80.         if(number>0){  
  81.             etNumber.setText(number+"");  
  82.         }  
  83.     }  
  84.     //对外提供一个获取当前数字的方法  
  85.     public int getNumber(){  
  86.         String string = etNumber.getText().toString();  
  87.         int i = Integer.parseInt(string);  
  88.         return i;  
  89.     }  
  90. }  
  91.   
  92. //---XML  
  93. <LinearLayout  
  94.     android:orientation="horizontal"  
  95.     xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"  
  96.     android:layout_height="match_parent">  
  97.     <TextView  
  98.         android:id="@+id/txt_minus"  
  99.         android:layout_width="35dp"  
  100.         android:layout_height="35dp"  
  101.         android:gravity="center"  
  102.         android:background="@drawable/shopcart_minus_grey"/>  
  103.   
  104.     <EditText  
  105.         android:id="@+id/et_number"  
  106.         android:layout_marginTop="2dp"  
  107.         android:layout_width="35dp"  
  108.         android:layout_height="35dp"  
  109.         android:background="@drawable/edit"  
  110.         android:layout_weight="0.00"  
  111.         android:gravity="center"  
  112.         android:text="1"/>  
  113.     <TextView  
  114.         android:id="@+id/txt_add"  
  115.         android:layout_width="35dp"  
  116.         android:layout_height="35dp"  
  117.         android:gravity="center"  
  118.         android:background="@drawable/shopcart_add_red"/>  
  119. LinearLayout>  
[html]  view plain  copy
  1. //MainActivity  
  2. public class MainActivity extends BaseActivity implements IShowCartView,View.OnClickListener {  
  3.   
  4.     private ExpandableListView expandable;  
  5.     private CheckBox checkBox;  
  6.     private TextView cart_priceAll;  
  7.     private TextView cart_count;  
  8.     private List<CartBean.DataBean> data;  
  9.     private CartAdapter cartAdapter;  
  10.     private ShowCartPresenter showCartPresenter;  
  11.     private TextView cart_editor;  
  12.     private boolean flag=true;  
  13.     private Button cart_jiesuan;  
  14.     private Button cart_delete;  
  15.   
  16.     @Override  
  17.     protected int bindLayout() {  
  18.         return R.layout.activity_main;  
  19.     }  
  20.   
  21.     @Override  
  22.     protected void initView() {  
  23.         showCartPresenter = new ShowCartPresenter(this);  
  24.         showCartPresenter.showCart("12400");  
  25.         cart_editor = findViewById(R.id.cart_editor);  
  26.         expandable = findViewById(R.id.cart_expandable);  
  27.         checkBox = findViewById(R.id.cart_checkBox);  
  28.         cart_priceAll = findViewById(R.id.cart_priceAll);  
  29.         cart_count = findViewById(R.id.cart_count);  
  30.         cart_jiesuan = findViewById(R.id.cart_jiesuan);  
  31.         cart_delete = findViewById(R.id.cart_delete);  
  32.     }  
  33.   
  34.     @Override  
  35.     protected void initData() {  
  36.   
  37.     }  
  38.   
  39.     @Override  
  40.     protected void setListener() {  
  41.         checkBox.setOnClickListener(this);  
  42.         cart_editor.setOnClickListener(this);  
  43.         cart_delete.setOnClickListener(this);  
  44.     }  
  45.   
  46.     @Override  
  47.     public void showCartSuccess(final List<CartBean.DataBean> data) {  
  48.         this.data=data;  
  49.         cartAdapter = new CartAdapter(MainActivity.this,data, this);  
  50.         expandable.setAdapter(cartAdapter);  
  51.         //展开所有的列表  
  52.         int childCount = cartAdapter.getGroupCount();  
  53.         for (int i = 0; i < childCount; i++) {  
  54.             expandable.expandGroup(i);  
  55.         }  
  56.     }  
  57.   
  58.     @Override  
  59.     public void showCartfailure(Throwable t) {  
  60.         Log.d("异常showCart", t.toString());  
  61.     }  
  62.   
  63.     @Override  
  64.     public void jisuan(String count, String priceAll) {  
  65.         cart_count.setText("共"+count+"件商品");  
  66.         cart_priceAll.setText("总计:"+priceAll);  
  67.     }  
  68.     //--------------------------------删除购物车  
  69.     @Override  
  70.     public void deleteCartSuccess(String str) {  
  71.         Toast.makeText(MainActivity.this,str,Toast.LENGTH_SHORT).show();  
  72.     }  
  73.   
  74.     @Override  
  75.     public void deleteCartfailure(Throwable t) {  
  76.         Log.d("异常deleteCart", t.toString());  
  77.     }  
  78.     //----------------------------------修改数量  
  79.     @Override  
  80.     public void updateCartsSuccess(String str) {  
  81.         Toast.makeText(MainActivity.this,str,Toast.LENGTH_SHORT).show();  
  82.     }  
  83.   
  84.     @Override  
  85.     public void updateCartsfailure(Throwable t) {  
  86.         Log.d("异常updateCarts", t.toString());  
  87.     }  
  88.   
  89.   
  90.     //----------------------点击事件  
  91.     @Override  
  92.     public void onClick(View v) {  
  93.         switch (v.getId()){  
  94.             case R.id.cart_checkBox:  
  95.                 for (int i = 0; i < data.size(); i++) {  
  96.                     data.get(i).setCheck(!data.get(i).isCheck());  
  97.                     List<CartBean.DataBean.ListBean> list = data.get(i).getList();  
  98.                     for (int j = 0; j < list.size(); j++) {  
  99.                         list.get(j).setCheck(!list.get(j).isCheck());  
  100.                     }  
  101.                 }  
  102.                 cartAdapter.jS();  
  103.                 cartAdapter.notifyDataSetChanged();  
  104.                 break;  
  105.             case R.id.cart_editor:  
  106.                 if (flag){  
  107.                     cart_editor.setText("完成");  
  108.                     cart_delete.setVisibility(View.VISIBLE);  
  109.                     cart_jiesuan.setVisibility(View.INVISIBLE);  
  110.                     cart_priceAll.setVisibility(View.INVISIBLE);  
  111.                     cart_count.setVisibility(View.INVISIBLE);  
  112.                     flag=false;  
  113.                 }else {  
  114.                     cart_editor.setText("编辑");  
  115.                     cart_delete.setVisibility(View.INVISIBLE);  
  116.                     cart_jiesuan.setVisibility(View.VISIBLE);  
  117.                     cart_priceAll.setVisibility(View.VISIBLE);  
  118.                     cart_count.setVisibility(View.VISIBLE);  
  119.                     flag=true;  
  120.                 }  
  121.                 break;  
  122.             case R.id.cart_delete:  
  123.                 List<CartBean.DataBean> toBeDeleteGroups = new ArrayList<CartBean.DataBean>();  
  124.                 //待删除的组元素  
  125.                 for (int i = 0; i < data.size(); i++) {  
  126.                     CartBean.DataBean group = data.get(i);  
  127.                     if (data.get(i).isCheck()) {  
  128.                         toBeDeleteGroups.add(group);  
  129.                     }  
  130.                     List<CartBean.DataBean.ListBean> toBeDeleteChilds = new ArrayList<CartBean.DataBean.ListBean>();//待删除的子元素  
  131.                     List<CartBean.DataBean.ListBean> list = data.get(i).getList();  
  132.                     for (int j = 0; j < list.size(); j++) {  
  133.                         if (list.get(j).isCheck()) {  
  134.                             toBeDeleteChilds.add(list.get(j));  
  135.                                 showCartPresenter.deleteCart("12400",list.get(j).getPid()+"");  
  136.   
  137.                         }  
  138.                     }  
  139.                     list.removeAll(toBeDeleteChilds);  
  140.                 }  
  141.                 data.removeAll(toBeDeleteGroups);  
  142.                 cart_count.setText("共"+0+"件商品");  
  143.                 cart_priceAll.setText("总计:"+0.0);  
  144.                 //重新设置购物车  
  145.                 cartAdapter.notifyDataSetChanged();  
  146.                 break;  
  147.         }  
  148.     }  
  149. }  
  150.   
  151. //---适配器  
  152. public class CartAdapter extends BaseExpandableListAdapter {  
  153.     private final IShowCartView IShowCartView;  
  154.     private final Context context;  
  155.     private final List<CartBean.DataBean> list;  
  156.     private GroupViewHolder holder;  
  157.     private ChildViewHolder childholder;  
  158.   
  159.   
  160.     public CartAdapter(Context context, List<CartBean.DataBean> data, IShowCartView IShowCartView) {  
  161.         this.IShowCartView=IShowCartView;  
  162.         this.context=context;  
  163.         this.list=data;  
  164.     }  
  165.     @Override  
  166.     public int getGroupCount() {  
  167.         return list.size();  
  168.     }  
  169.   
  170.     @Override  
  171.     public int getChildrenCount(int groupPosition) {  
  172.         return list.get(groupPosition).getList().size();  
  173.     }  
  174.     @Override  
  175.     public Object getGroup(int groupPosition) {  
  176.         return list.get(groupPosition);  
  177.     }  
  178.     @Override  
  179.     public Object getChild(int groupPosition, int childPosition) {  
  180.         return list.get(groupPosition).getList().get(childPosition);  
  181.     }  
  182.     @Override  
  183.     public long getGroupId(int groupPosition) {  
  184.         return groupPosition;  
  185.     }  
  186.     @Override  
  187.     public long getChildId(int groupPosition, int childPosition) {  
  188.         return childPosition;  
  189.     }  
  190.     @Override  
  191.     public boolean hasStableIds() {  
  192.         return false;  
  193.     }  
  194.     @Override  
  195.     public View getGroupView(final int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {  
  196.         if(convertView==null){  
  197.             holder = new GroupViewHolder();  
  198.             convertView = View.inflate(context, R.layout.cart_groupitem, null);  
  199.             holder.group_box = convertView.findViewById(R.id.group_box);  
  200.             holder.group_name = convertView.findViewById(R.id.group_name);  
  201.             convertView.setTag(holder);  
  202.         }else{  
  203.             holder = (GroupViewHolder) convertView.getTag();  
  204.         }  
  205.         holder.group_box.setChecked(list.get(groupPosition).isCheck());  
  206.         holder.group_name.setText(list.get(groupPosition).getSellerName());  
  207.         holder.group_box.setOnClickListener(new View.OnClickListener() {  
  208.             @Override  
  209.             public void onClick(View v) {  
  210.                 boolean isCleked = list.get(groupPosition).isCheck();  
  211.                 isCleked=!isCleked;  
  212.                 list.get(groupPosition).setCheck(isCleked);  
  213.                 List<CartBean.DataBean.ListBean> beans = CartAdapter.this.list.get(groupPosition).getList();  
  214.                 for (int i = 0; i < beans.size() ; i++) {  
  215.                     beans.get(i).setCheck(isCleked);  
  216.                 }  
  217.                 jS();  
  218.                 notifyDataSetChanged();  
  219.             }  
  220.         });  
  221.         return convertView;  
  222.     }  
  223.     @Override  
  224.     public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {  
  225.         if (convertView==null){  
  226.             convertView = View.inflate(context, R.layout.cart_childitem, null);  
  227.             childholder = new ChildViewHolder();  
  228.             childholder.child_box = convertView.findViewById(R.id.child_box);  
  229.             childholder.child_img = convertView.findViewById(R.id.child_img);  
  230.             childholder.child_subhead = convertView.findViewById(R.id.child_subhead);  
  231.             childholder.child_price = convertView.findViewById(R.id.child_price);  
  232.             childholder.child_adm = convertView.findViewById(R.id.child_adm);  
  233.             convertView.setTag(childholder);  
  234.         }else{  
  235.             childholder = (ChildViewHolder) convertView.getTag();  
  236.         }  
  237.         childholder.child_box.setChecked(list.get(groupPosition).getList().get(childPosition).isCheck());  
  238.         String images = list.get(groupPosition).getList().get(childPosition).getImages();  
  239.         String image = images.split(".jpg")[0] + ".jpg";  
  240.         childholder.child_img.setImageURI(Uri.parse(image));  
  241.         childholder.child_subhead.setText(list.get(groupPosition).getList().get(childPosition).getSubhead());  
  242.         childholder.child_price.setText("售价为:"+list.get(groupPosition).getList().get(childPosition).getPrice());  
  243.         childholder.child_adm.setNumber(list.get(groupPosition).getList().get(childPosition).getNum());  
  244.         childholder.child_box.setOnClickListener(new View.OnClickListener() {  
  245.             @Override  
  246.             public void onClick(View v) {  
  247.                 boolean isCleked = list.get(groupPosition).getList().get(childPosition).isCheck();  
  248.                 isCleked=!isCleked;  
  249.                 list.get(groupPosition).getList().get(childPosition).setCheck(isCleked);  
  250.                 List<CartBean.DataBean.ListBean> beans = CartAdapter.this.list.get(groupPosition).getList();  
  251.                 boolean flag=true;  
  252.                 for (int i = 0; i < beans.size() ; i++) {  
  253.                     if (!beans.get(i).isCheck()) {  
  254.                         flag=false;  
  255.                     }  
  256.                 }  
  257.                 list.get(groupPosition).setCheck(flag);  
  258.                 jS();  
  259.                 notifyDataSetChanged();  
  260.             }  
  261.         });  
  262.         childholder.child_adm.setOnAddMinusClickListener(new AddMinusView.OnAddMinusClickListener() {  
  263.             @Override  
  264.             public void onAddClick(View v) {  
  265.                 int num = list.get(groupPosition).getList().get(childPosition).getNum();  
  266.                 num++;  
  267.                 list.get(groupPosition).getList().get(childPosition).setNum(num);  
  268.                 jS();  
  269.                 notifyDataSetChanged();  
  270.             }  
  271.             @Override  
  272.             public void onMinusClick(View v) {  
  273.                 int num = list.get(groupPosition).getList().get(childPosition).getNum();  
  274.                 num--;  
  275.                 if(num<=0) {  
  276.                     Toast.makeText(context, "最小数量为1", Toast.LENGTH_SHORT).show();  
  277.                     return;  
  278.                 }  
  279.                 list.get(groupPosition).getList().get(childPosition).setNum(num);  
  280.                 jS();  
  281.                 notifyDataSetChanged();  
  282.             }  
  283.   
  284.             @Override  
  285.             public void onEtNumberClick(View v) {  
  286.                 final AlertDialog builder = new AlertDialog.Builder(context).create();  
  287.                 builder.setTitle("温馨提示");  
  288.                 View inflate = View.inflate(context, R.layout.cart_update, null);  
  289.                 builder.setView(inflate);  
  290.                 TextView add = inflate.findViewById(R.id.goods_add);  
  291.                 TextView minus = inflate.findViewById(R.id.goods_minus);  
  292.                 final EditText goods_num = inflate.findViewById(R.id.goods_num);  
  293.                 Button cancel = inflate.findViewById(R.id.goods_cancel);  
  294.                 Button confirm = inflate.findViewById(R.id.goods_confirm);  
  295.                 goods_num.setText(list.get(groupPosition).getList().get(childPosition).getNum()+"");  
  296.                 add.setOnClickListener(new View.OnClickListener() {  
  297.                     @Override  
  298.                     public void onClick(View v) {  
  299.                         int num = Integer.parseInt(goods_num.getText().toString());  
  300.                         num++;  
  301.                         goods_num.setText(num+"");  
  302.                     }  
  303.                 });  
  304.                 minus.setOnClickListener(new View.OnClickListener() {  
  305.                     @Override  
  306.                     public void onClick(View v) {  
  307.                         int num = Integer.parseInt(goods_num.getText().toString());  
  308.                         num--;  
  309.                         if(num<=0) {  
  310.                             Toast.makeText(context, "最小数量为1", Toast.LENGTH_SHORT).show();  
  311.                             return;  
  312.                         }  
  313.                         goods_num.setText(num+"");  
  314.                     }  
  315.                 });  
  316.                 confirm.setOnClickListener(new View.OnClickListener() {  
  317.                     private String uid;  
  318.                     @Override  
  319.                     public void onClick(View v) {  
  320.                         CartBean.DataBean.ListBean bean = list.get(groupPosition).getList().get(childPosition);  
  321.                         new ShowCartPresenter(IShowCartView).updateCarts("12400",bean.getSellerid()+"",bean.getPid()+"",bean.getSelected()+"",goods_num.getText().toString());  
  322.                         list.get(groupPosition).getList().get(childPosition).setNum(Integer.parseInt(goods_num.getText().toString()));  
  323.                         notifyDataSetChanged();  
  324.                         builder.dismiss();  
  325.                     }  
  326.                 });  
  327.                 builder.show();  
  328.             }  
  329.         });  
  330.   
  331.         return convertView;  
  332.     }  
  333.     @Override  
  334.     public boolean isChildSelectable(int groupPosition, int childPosition) {  
  335.         return false;  
  336.     }  
  337.     class GroupViewHolder{  
  338.         public CheckBox group_box;  
  339.         public TextView group_name;  
  340.     }  
  341.     class ChildViewHolder{  
  342.         public CheckBox child_box;  
  343.         public ImageView child_img;  
  344.         public TextView child_subhead;  
  345.         public TextView child_price;  
  346.         public AddMinusView child_adm;  
  347.   
  348.     }  
  349.   
  350.     /**  
  351.      * 计算数量和价格  
  352.      * 通过遍历一级的得到二级的CheckBox,如果是选择的选中状态的话,就统计它们的总计的数量和价格  
  353.      */  
  354.     public void jS(){  
  355.         double priceAll = 0;  
  356.         int cou=0;  
  357.         for (int i = 0; i <list.size() ; i++) {  
  358.             List<CartBean.DataBean.ListBean> beans = this.list.get(i).getList();  
  359.             for (int j = 0; j <beans.size() ; j++) {  
  360.                 boolean check = beans.get(j).isCheck();  
  361.                 if(check==true){  
  362.                     double mul = JisuanUtils.mul(beans.get(j).getPrice(), beans.get(j).getNum());  
  363.                     priceAll = JisuanUtils.add(priceAll, mul);  
  364.                     cou+=beans.get(j).getNum();  
  365.                 }  
  366.             }  
  367.         }  
  368.         Log.d("数据呢", cou+"");  
  369.         IShowCartView.jisuan(cou+"",priceAll+"");  
  370.     }  
  371. }  

[html]  view plain  copy
  1. //values下  
  2. //attrs.xml  
  3.  xml version="1.0" encoding="utf-8"?>  
  4. <resources>  
  5.     <declare-styleable name="AddMinusViewStyle">  
  6.   
  7.         <attr name="left_text" format="string"/>  
  8.   
  9.         <attr name="right_text" format="string"/>  
  10.         <attr name="middle_text" format="integer"/>  
  11.   
  12.         <attr name="left_text_color" format="color"/>  
  13.     declare-styleable>  
  14. resources>  
  15.   
  16. //---color.XML  
  17. xml version="1.0" encoding="utf-8"?>  
  18. <resources>  
  19.     <color name="colorPrimary">#3F51B5color>  
  20.     <color name="colorPrimaryDark">#303F9Fcolor>  
  21.     <color name="colorAccent">#FF4081color>  
  22.     <color name="Cornsilk">#FFF8DCcolor>  
  23.     <color name="BlueViolet">#8A2BE2color>  
  24.     <color name="White">#FFFFFFcolor>  
  25.     <color name="Silver">#C0C0C0color>  
  26.     <color name="Red">#FF0000color>  
  27.     <color name="Black">#000000color>  
  28. resources>  


[html]  view plain  copy
  1. //mapp全局初始化  
  2. public class MApp extends Application {  
  3.     @Override  
  4.     public void onCreate() {  
  5.         super.onCreate();  
  6.         Fresco.initialize(this);  
  7.     }  
  8. }  

[html]  view plain  copy
  1. //drawable下  
  2. //edit.XML  
  3. xml version="1.0" encoding="utf-8"?>  
  4. <shape xmlns:android="http://schemas.android.com/apk/res/android">  
  5.     <solid android:color="#FFFFFF" />  
  6.     <stroke  
  7.         android:width="1dip"  
  8.         android:color="#BDC7D8" />  
  9. shape>  

[html]  view plain  copy
  1. //main的XML  
  2. xml version="1.0" encoding="utf-8"?>  
  3. <LinearLayout  
  4.     android:orientation="vertical"  
  5.     xmlns:android="http://schemas.android.com/apk/res/android"  
  6.     xmlns:app="http://schemas.android.com/apk/res-auto"  
  7.     xmlns:tools="http://schemas.android.com/tools"  
  8.     android:layout_width="match_parent"  
  9.     android:layout_height="match_parent"  
  10.     tools:context="com.example.hp.lianjunnan0406.MainActivity">  
  11.     <RelativeLayout  
  12.         android:layout_width="match_parent"  
  13.         android:layout_height="70dp"  
  14.         android:background="@color/BlueViolet">  
  15.         <TextView  
  16.             android:layout_width="wrap_content"  
  17.             android:layout_height="wrap_content"  
  18.             android:text="购物车"  
  19.             android:textSize="25dp"  
  20.             android:layout_centerVertical="true"  
  21.             android:layout_centerHorizontal="true"  
  22.             android:layout_weight="1"  
  23.             />  
  24.         <TextView  
  25.             android:id="@+id/cart_editor"  
  26.             android:layout_width="wrap_content"  
  27.             android:layout_height="wrap_content"  
  28.             android:text="编辑"  
  29.             android:layout_centerVertical="true"  
  30.             android:layout_alignParentRight="true"  
  31.             android:layout_marginRight="37dp"  
  32.             />  
  33.     RelativeLayout>  
  34.   
  35.     <ExpandableListView  
  36.         android:groupIndicator="@null"  
  37.         android:layout_weight="1"  
  38.         android:layout_width="wrap_content"  
  39.         android:layout_height="wrap_content"  
  40.         android:id="@+id/cart_expandable"  
  41.         >  
  42.     ExpandableListView>  
  43.     <View  
  44.         android:layout_width="match_parent"  
  45.         android:layout_height="0.75dp"  
  46.         android:background="@color/colorPrimary"  
  47.         >View>  
  48.     <RelativeLayout  
  49.         android:layout_width="match_parent"  
  50.         android:layout_height="50dp"  
  51.         android:id="@+id/gwc_item_linear"  
  52.         >  
  53.         <CheckBox  
  54.             android:layout_width="wrap_content"  
  55.             android:layout_height="wrap_content"  
  56.             android:layout_centerVertical="true"  
  57.             android:id="@+id/cart_checkBox"  
  58.             />  
  59.         <TextView  
  60.             android:layout_width="wrap_content"  
  61.             android:layout_height="wrap_content"  
  62.             android:layout_centerVertical="true"  
  63.             android:layout_toRightOf="@+id/cart_checkBox"  
  64.             android:text="全选/反选"/>  
  65.   
  66.         <TextView  
  67.             android:id="@+id/cart_priceAll"  
  68.             android:layout_width="wrap_content"  
  69.             android:layout_height="wrap_content"  
  70.             android:layout_centerHorizontal="true"  
  71.             android:layout_marginTop="5dp"  
  72.             android:text="总价:0.0"  
  73.             />  
  74.         <TextView  
  75.             android:text="共0件商品"  
  76.             android:id="@+id/cart_count"  
  77.             android:layout_below="@+id/cart_priceAll"  
  78.             android:layout_centerHorizontal="true"  
  79.             android:layout_marginTop="5dp"  
  80.             android:layout_width="wrap_content"  
  81.             android:layout_height="wrap_content" />  
  82.   
  83.         <Button  
  84.             android:id="@+id/cart_jiesuan"  
  85.             android:layout_width="50dp"  
  86.             android:layout_height="30dp"  
  87.             android:background="@color/White"  
  88.             android:textColor="@color/BlueViolet"  
  89.             android:layout_centerVertical="true"  
  90.             android:layout_alignParentRight="true"  
  91.             android:layout_marginRight="30dp"  
  92.             android:text="去结算" />  
  93.         <Button  
  94.             android:id="@+id/cart_delete"  
  95.             android:layout_width="50dp"  
  96.             android:layout_height="30dp"  
  97.             android:background="@color/White"  
  98.             android:textColor="@color/Red"  
  99.             android:layout_centerVertical="true"  
  100.             android:layout_toLeftOf="@+id/cart_jiesuan"  
  101.             android:visibility="invisible"  
  102.             android:text="删除" />  
  103.   
  104.     RelativeLayout>  
  105.   
  106. LinearLayout>  

[html]  view plain  copy
  1. //适配器子布局  
  2. xml version="1.0" encoding="utf-8"?>  
  3. <RelativeLayout  
  4.     android:orientation="horizontal"  
  5.     xmlns:android="http://schemas.android.com/apk/res/android"  
  6.     android:layout_width="match_parent"  
  7.     android:layout_height="100dp">  
  8.     <CheckBox  
  9.         android:layout_width="wrap_content"  
  10.         android:layout_height="wrap_content"  
  11.         android:layout_centerVertical="true"  
  12.         android:id="@+id/child_box"/>  
  13.     <com.facebook.drawee.view.SimpleDraweeView  
  14.         android:id="@+id/child_img"  
  15.         android:layout_width="100dp"  
  16.         android:layout_height="100dp"  
  17.         android:layout_centerVertical="true"  
  18.         android:layout_toRightOf="@+id/child_box"  
  19.         android:background="@color/Red"  
  20.         roundAsCircle="true"/>  
  21.     <TextView  
  22.         android:layout_width="wrap_content"  
  23.         android:layout_height="wrap_content"  
  24.         android:id="@+id/child_subhead"  
  25.         android:layout_toRightOf="@+id/child_img"  
  26.         android:layout_marginLeft="10dp"  
  27.         android:layout_marginTop="10dp"  
  28.         android:text="标题"  
  29.         />  
  30.   
  31.     <TextView  
  32.         android:layout_width="wrap_content"  
  33.         android:layout_height="wrap_content"  
  34.         android:id="@+id/child_price"  
  35.         android:layout_toRightOf="@+id/child_img"  
  36.         android:layout_marginLeft="10dp"  
  37.         android:layout_marginTop="70dp"  
  38.         android:text="价格"  
  39.         />  
  40.   
  41.     <com.example.hp.lianjunnan0406.view.AddMinusView  
  42.         android:id="@+id/child_adm"  
  43.         android:layout_width="110dp"  
  44.         android:layout_height="40dp"  
  45.         android:layout_alignParentRight="true"  
  46.         android:layout_marginRight="40dp"  
  47.         android:layout_marginTop="60dp"  
  48.         android:focusable="false"  >  
  49.     com.example.hp.lianjunnan0406.view.AddMinusView>  
  50.   
  51. RelativeLayout>  

[html]  view plain  copy
  1. //适配器父布局  
  2. xml version="1.0" encoding="utf-8"?>  
  3. <LinearLayout  
  4.     android:orientation="horizontal"  
  5.     xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"  
  6.     android:layout_height="match_parent">  
  7.     <CheckBox  
  8.         android:layout_width="wrap_content"  
  9.         android:layout_height="wrap_content"  
  10.         android:id="@+id/group_box"  
  11.         />  
  12.     <TextView  
  13.         android:layout_width="wrap_content"  
  14.         android:layout_height="wrap_content"  
  15.         android:id="@+id/group_name"  
  16.         />  
  17. LinearLayout>  

[html]  view plain  copy
  1. //适配器弹框  
  2. xml version="1.0" encoding="utf-8"?>  
  3. <LinearLayout  
  4.     android:orientation="vertical"  
  5.     xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"  
  6.     android:layout_height="match_parent">  
  7.     <LinearLayout  
  8.         android:layout_width="match_parent"  
  9.         android:layout_height="wrap_content"  
  10.         android:gravity="center_horizontal"  
  11.         android:orientation="horizontal">  
  12.         <TextView  
  13.             android:id="@+id/goods_minus"  
  14.             android:layout_width="35dp"  
  15.             android:layout_height="35dp"  
  16.             android:gravity="center"  
  17.             android:background="@drawable/shopcart_minus_grey"/>  
  18.   
  19.         <EditText  
  20.             android:id="@+id/goods_num"  
  21.             android:layout_marginTop="2dp"  
  22.             android:layout_width="100dp"  
  23.             android:layout_height="35dp"  
  24.             android:background="@drawable/edit"  
  25.             android:layout_weight="0.00"  
  26.             android:gravity="center"  
  27.             android:text="1"/>  
  28.         <TextView  
  29.             android:id="@+id/goods_add"  
  30.             android:layout_width="35dp"  
  31.             android:layout_height="35dp"  
  32.             android:gravity="center"  
  33.             android:background="@drawable/shopcart_add_red"/>  
  34.     LinearLayout>  
  35.     <LinearLayout  

你可能感兴趣的:(购物车)