京东购物车

依赖:

annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
compile 'com.android.support:recyclerview-v7:26.1.0'
//注意版本
compile 'com.squareup.retrofit2:retrofit:2.0.1'
// Okhttp库
compile 'com.squareup.okhttp3:okhttp:3.1.2'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
// Retrofit库
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
compile 'com.squareup.retrofit2:converter-gson:2.4.0'
compile 'com.squareup.retrofit2:adapter-rxjava2:2.4.0'
// rxjava+rxandroid+retrofit2+okhttp
implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
implementation 'io.reactivex.rxjava2:rxjava:2.1.12'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.squareup.okhttp3:logging-interceptor:3.4.1'
compile 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
compile 'org.greenrobot:eventbus:3.0.0'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.facebook.fresco:fresco:0.12.0'

bean:

MessageBean:

public class MessageBean<T> {

    /**
     * code : 0
     * data : [{"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","itemtype":1,"pid":20,"price":599,"pscid":1,"salenum":10000,"sellerid":13,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"},{"bargainPrice":111.99,"createtime":"2017-10-03T23:53:28","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","itemtype":0,"pid":8,"price":324,"pscid":1,"salenum":3000,"sellerid":1,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"},{"bargainPrice":111.99,"createtime":"2017-10-14T21:48:08","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","itemtype":2,"pid":9,"price":78.99,"pscid":1,"salenum":2356,"sellerid":2,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"},{"bargainPrice":111.99,"createtime":"2017-10-14T21:48:08","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","itemtype":2,"pid":22,"price":799,"pscid":1,"salenum":1300,"sellerid":15,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"},{"bargainPrice":111.99,"createtime":"2017-10-03T23:53:28","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","itemtype":0,"pid":21,"price":699,"pscid":1,"salenum":1299,"sellerid":14,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"},{"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","itemtype":1,"pid":7,"price":120.01,"pscid":1,"salenum":1266,"sellerid":23,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"},{"bargainPrice":111.99,"createtime":"2017-10-03T23:53:28","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","itemtype":0,"pid":3,"price":198,"pscid":1,"salenum":1234,"sellerid":19,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"},{"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","itemtype":1,"pid":19,"price":499,"pscid":1,"salenum":1111,"sellerid":12,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"},{"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","itemtype":1,"pid":2,"price":299,"pscid":1,"salenum":999,"sellerid":18,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"},{"bargainPrice":111.99,"createtime":"2017-10-03T23:53:28","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","itemtype":0,"pid":17,"price":299,"pscid":1,"salenum":888,"sellerid":10,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}]
     * msg : 请求成功
     * page : 1
     */

    private String code;
    private String msg;
    private String page;
    private T data;

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getPage() {
        return page;
    }

    public void setPage(String page) {
        this.page = page;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }


}

shopBean:

public class ShopBean {


        /**
         * 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
         * itemtype : 1
         * pid : 20
         * price : 599.0
         * pscid : 1
         * salenum : 10000
         * sellerid : 13
         * subhead : 每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下
         * title : 北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g
         */

        private double bargainPrice;
        private String createtime;
        private String detailUrl;
        private String images;
        private int itemtype;
        private int pid;
        private double price;
        private int pscid;
        private int salenum;
        private int sellerid;
        private String subhead;
        private String title;
        private boolean ischeck;

    public ShopBean(boolean ischeck) {
        this.ischeck = ischeck;
    }

    public boolean isIscheck() {
        return ischeck;
    }

    public void setIscheck(boolean ischeck) {
        this.ischeck = ischeck;
    }

    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 getItemtype() {
            return itemtype;
        }

        public void setItemtype(int itemtype) {
            this.itemtype = itemtype;
        }

        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 getSalenum() {
            return salenum;
        }

        public void setSalenum(int salenum) {
            this.salenum = salenum;
        }

        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;
        }
    }


http:

Apiservice接口:

@GET("product/getProducts")
Observable<MessageBean<List<ShopBean>>> getShop(@Query("pscid")String cid);


ServiceURL:

public static final String BASE_URL="https://www.zhaoapi.cn/";

inter包:



IPresenter:

public interface Ipresenter<T> {
    void onReceived(T t);
    void onError(Throwable t);
}
 
 
IView:
public interface IView<T> {
    void onSuccess(T t);
    void onFailed(Throwable t);
}


Shopmodel:

public class Shopmodel {
    private Ipresenter presenter;
    public Shopmodel(Ipresenter presenter) {
        this.presenter = presenter;
    }

    public void getData(String cid) {
        HttpUtils.getInstance().getService()
                .getShop(cid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<MessageBean<List<ShopBean>>>() {

                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(MessageBean<List<ShopBean>> listMessageBean) {
                     //   Log.i("--", "onNext: "+listMessageBean.toString());
                        presenter.onReceived(listMessageBean);
                    }



                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}

ShopPresenter :
public class ShopPresenter implements Ipresenter<MessageBean<List<ShopBean>>> {
    private IView iv;

    public void attachView(IView iv) {
        this.iv = iv;
    }

    public void detachView() {
        if (iv != null) {
            iv = null;
        }
    }

    public void getData(String cid) {
        Shopmodel model = new Shopmodel(this);
        model.getData(cid);
    }








    @Override
    public void onReceived(MessageBean<List<ShopBean>> listMessageBean) {
      //  Log.i("--", "onNext: "+listMessageBean.toString());
        iv.onSuccess(listMessageBean);
    }

    @Override
    public void onError(Throwable t) {
        iv.onFailed(t);
    }

}
View包:
public class Fragmentthree extends Fragment implements IView<MessageBean<List<ShopBean>>>,ShopAdapter.ChangeData {
    @BindView(R.id.rv)
    RecyclerView rv;
    @BindView(R.id.quan)
    CheckBox quan;
    @BindView(R.id.price)
    TextView price;
    @BindView(R.id.but)
    Button but;
    Unbinder unbinder;
    private List<ShopBean> list;
    private ShopAdapter shopAdapter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.three, container, false);
        unbinder = ButterKnife.bind(this, view);
        ShopPresenter shopPresenter = new ShopPresenter();
        shopPresenter.attachView(this);
        shopPresenter.getData("1");
        list = new ArrayList<>();
        rv.setLayoutManager(new StaggeredGridLayoutManager(1,StaggeredGridLayoutManager.VERTICAL));
        shopAdapter = new ShopAdapter(getActivity(), list);
        shopAdapter.setShoping(this);

        rv.setAdapter(shopAdapter);
        return view;
    }

    @Override
    public void onSuccess(MessageBean<List<ShopBean>> listMessageBean) {

        if (listMessageBean != null) {
            List<ShopBean> data = listMessageBean.getData();


            if (data != null) {
                this.list.addAll(data);
                shopAdapter.notifyDataSetChanged();
            }
        }
        getMoney();
    }

    @Override
    public void onFailed(Throwable t) {

    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    private void getMoney() {
        DecimalFormat    df   = new DecimalFormat("######0.00");

        double zon = 0;
        int num = 0;
        for (int i = 0; i < list.size(); i++) {
            ShopBean shopBean = list.get(i);
            if (shopBean.isIscheck()) {
                double price = shopBean.getPrice();
                int sellerid = shopBean.getSellerid();
                zon += price * sellerid;
                num +=sellerid;
            }
        }
        price.setText("总价:" + df.format(zon));
        but.setText("结算("+num+")");
        shopAdapter.notifyDataSetChanged();
    }
    @Override
    public void jiaNum(int position) {
        ShopBean shopBean = list.get(position);
        int sellerid = shopBean.getSellerid();
        sellerid++;
        shopBean.setSellerid(sellerid);

        getMoney();
    }

    @Override
    public void jianNum(int position, Button but) {
        ShopBean shopBean = list.get(position);
        int sellerid = shopBean.getSellerid();

        if (sellerid == 1) {
            but.setFocusable(false);
            Toast.makeText(getActivity(), "最少数量为1", Toast.LENGTH_SHORT).show();
        } else {
            sellerid--;
        }
        shopBean.setSellerid(sellerid);

        getMoney();
    }

    @Override
    public void click(int position, boolean ischeck, CheckBox checkBox) {
        list.get(position).setIscheck(ischeck);
        shopAdapter.notifyDataSetChanged();
        getMoney();
    }

    @Override
    public void removeMoney() {
        getMoney();
    }

    @OnClick(R.id.quan)
    public void onViewClicked() {
        for (int i = 0; i < list.size(); i++) {
            list.get(i).setIscheck(quan.isChecked());
        }
        shopAdapter.notifyDataSetChanged();
        getMoney();
    }
}

Abapter包:
ShopAdapter
public class ShopAdapter extends RecyclerView.Adapter {
    Context context;
    List<ShopBean> list;
    @BindView(R.id.lv_checkbox)
    CheckBox lvCheckbox;
    @BindView(R.id.lv_img)
    ImageView lvImg;
    @BindView(R.id.lv_title)
    TextView lvTitle;
    @BindView(R.id.lv_price)
    TextView lvPrice;
    @BindView(R.id.lv_jian)
    Button lvJian;
    @BindView(R.id.lv_num)
    TextView lvNum;
    @BindView(R.id.lv_jia)
    Button lvJia;
    @BindView(R.id.lv_remove)
    Button lvRemove;

    public ShopAdapter(Context context, List<ShopBean> list) {
        this.context = context;
        this.list = list;
    }
    ChangeData changeData;

    public void setShoping(ChangeData changeData){
        this.changeData = changeData;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.shopitem, null);
        Myviewholder holder = new Myviewholder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        final Myviewholder myviewholder = (Myviewholder) holder;
        myviewholder.lv_title.setText(list.get(position).getTitle());
        myviewholder.lv_price.setText("价格:" +list.get(position).getPrice());
        myviewholder.lv_num.setText(list.get(position).getSellerid()+"");

        myviewholder.lv_checkbox.setChecked(list.get(position).isIscheck());
        String[] split = list.get(position).getImages().split("\\|");
        Glide.with(context).load(split[0]).into(myviewholder.lv_img);


        //全选
        myviewholder.lv_checkbox.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                list.get(position).setIscheck(!list.get(position).isIscheck());
                changeData.click(position,list.get(position).isIscheck(),myviewholder.lv_checkbox);
            }
        });

        //删除
        myviewholder.lv_remove.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                AlertDialog.Builder builder = new AlertDialog.Builder(context);
                builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        list.get(position).setIscheck(false);
                        changeData.removeMoney();
                        list.remove(position);

                        notifyDataSetChanged();
                    }
                });
                builder.setTitle("警告");
                builder.setMessage("确定删除嘛?");
                builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                });
                builder.show();

            }
        });

        //加
        myviewholder.lv_jia.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                changeData.jiaNum(position);
            }
        });
        //减
        myviewholder.lv_jian.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                changeData.jianNum(position,myviewholder.lv_jian);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class Myviewholder extends RecyclerView.ViewHolder {


        private final TextView lv_title;
        private final TextView lv_price;
        private final TextView lv_num;

        private final ImageView lv_img;
        private final CheckBox lv_checkbox;
        private final Button lv_jia;
        private final Button lv_jian;
        private final Button lv_remove;

        public Myviewholder(View itemView) {

            super(itemView);
            lv_title = itemView.findViewById(R.id.lv_title);
            lv_price = itemView.findViewById(R.id.lv_price);
            lv_num = itemView.findViewById(R.id.lv_num);

            lv_img = itemView.findViewById(R.id.lv_img);

            lv_checkbox = itemView.findViewById(R.id.lv_checkbox);
            lv_jia = itemView.findViewById(R.id.lv_jia);
            lv_jian = itemView.findViewById(R.id.lv_jian);
            lv_remove = itemView.findViewById(R.id.lv_remove);


        }
    }
    public interface ChangeData{
        void jiaNum(int position);
        void jianNum(int position,Button but);
        void click(int position, boolean ischeck, CheckBox checkBox);
        void removeMoney();
    }
}

布局:
shopitem:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:orientation="horizontal"
    xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <CheckBox
        android:layout_gravity="center"
        android:id="@+id/lv_checkbox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />
    <ImageView
        android:id="@+id/lv_img"
        android:layout_gravity="center"
        android:layout_width="100dp"
        android:layout_height="100dp" />
    <LinearLayout
        android:orientation="vertical"
        android:layout_gravity="center"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content">
        <TextView
            android:id="@+id/lv_title"
            android:text="标题"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <TextView

                android:id="@+id/lv_price"
                android:text="价格:0.0"
                android:layout_width="120dp"
                android:layout_height="wrap_content" />
            <Button
                android:id="@+id/lv_jian"
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:text="-"/>
            <TextView
                android:id="@+id/lv_num"
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:text="0"/>
            <Button
                android:id="@+id/lv_jia"
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:text="+"/>
        </LinearLayout>


    </LinearLayout>
    <Button
        android:id="@+id/lv_remove"
        android:layout_gravity="center"
        android:layout_width="80dp"
        android:layout_height="wrap_content"
        android:text="删除"/>

</LinearLayout>

 
主布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <include layout="@layout/activity_title"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_marginTop="10dp"
        />

    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:id="@+id/rv">

    </android.support.v7.widget.RecyclerView>

    <LinearLayout
        android:gravity="center_vertical"
        android:layout_width="match_parent"
        android:layout_height="50dp">

        <CheckBox
            android:id="@+id/quan"
            android:layout_weight="1"
            android:text="全选"
            android:layout_width="0dp"
            android:layout_height="wrap_content" />
        <TextView
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:id="@+id/price"/>
        <Button
            android:id="@+id/but"
            android:textColor="#fff"
            android:background="#f00"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="结算"/>

    </LinearLayout>

</LinearLayout>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值