MVP+OkHttp 购物车

Android中添加商品的购物车 开发工具与关键技术:eclipse、Android 作者:邓婵 撰写时间:2020年 08月08日 Android中将商品添加进购物车首先我们要创建一个适配器,什么是适配器呢?适配器是数据和视图之间的桥梁,以便于数据在View上显示,就像显示器,把复杂的东西按人可以接受的方式来展现。下面就是我在适配器中设置点击事件方法以及绑定相关的数据。 然后设置适配器也就是把适配器给扔过来使用,相关代码如图下所示: 接着设置点击添加购物车按钮的方法将你需要添加的商品添加进去,向服务器发送请求,相关代码可参考图下: 阅读详情
//导包
compile 'com.google.code.gson:gson:2.6.2'

    compile 'com.squareup.okhttp3:okhttp:3.3.0'

    compile 'com.github.bumptech.glide:glide:3.7.0'
//activity_main
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.daydayup.day14_gouwuche.view.MainActivity">

    <ExpandableListView
        android:id="@+id/expandable_list_view"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:groupIndicator="@null"
        android:layout_weight="1"></ExpandableListView>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <CheckBox
            android:id="@+id/cb"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <TextView
            android:id="@+id/tv_sum"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="合计:0" />

        <Button
            android:id="@+id/jisuan"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="#F00"
            android:text="去结算(0)" />
    </LinearLayout>
</LinearLayout>
//item_parent
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <CheckBox
        android:id="@+id/parent_cb"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/parent_title"
        android:text="商家"
        android:singleLine="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>
//item_child
<?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="wrap_content"
    android:gravity="center_vertical"
    android:orientation="horizontal">

    <CheckBox
        android:id="@+id/child_cb"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <ImageView
        android:id="@+id/child_pic"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:src="@mipmap/ic_launcher" />

    <LinearLayout
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <TextView
            android:id="@+id/child_title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:singleLine="true"
            android:text="商品名"
            android:textSize="25sp" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/child_price"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:singleLine="true"
                android:text="商品价格"
                android:textColor="#F00" />

            <com.daydayup.day14_gouwuche.view.custumviews.AddSubView
                android:layout_width="100dp"
                android:id="@+id/addSubView"
                android:layout_height="30dp"></com.daydayup.day14_gouwuche.view.custumviews.AddSubView>
        </LinearLayout>

    </LinearLayout>
    <TextView
        android:id="@+id/dele"
        android:background="#F00"
        android:text="删除"
        android:gravity="center"
        android:layout_width="50dp"
        android:layout_height="match_parent" />

</LinearLayout>
//add_layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="100dp"
    android:layout_height="wrap_content"
    android:background="@drawable/add_shape"
    android:gravity="center_vertical"
    android:orientation="horizontal">

    <TextView
        android:gravity="center"
        android:id="@+id/sub"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:background="@drawable/add_shape"
        android:text="-" />

    <EditText

        android:id="@+id/count"
        android:layout_width="50dp"
        android:layout_height="30dp"
        android:background="@null" />

    <TextView
        android:gravity="center"
        android:id="@+id/add"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:background="@drawable/add_shape"
        android:text="+" />
</LinearLayout>
//drawable
//add_shape
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <size
        android:width="100dp"
        android:height="30dp" />
    <stroke
        android:width="1dp"
        android:color="#999999" />

</shape>
//model
//IModel
package com.daydayup.day14_gouwuche.model;

import java.util.List;
import java.util.Map;

/**
 * Model
 *
 *      MVP
 *          m---获取数据
 *          v---显示视图
 *          p---逻辑
 *
 */

public interface IModel {
    //获取购物车数据
    void getGouWuCheData(String url, Map<String,String> map,GouWuCheListener gouWuCheListener);
    //计算总价
    void jisuan(List<GouWuBean.DataBean> list,JiSuanListener jiSuanListener);
}
//ModelImpl
package com.daydayup.day14_gouwuche.model;

import android.util.Log;

import com.daydayup.day14_gouwuche.http.HttpUtils;
import com.daydayup.day14_gouwuche.http.OkLoadListener;

import java.util.List;
import java.util.Map;

/**
 * Created by gjl on 2018/4/25.
 */

public class ModelImpl implements IModel {
    private static final String TAG = "ModelImpl---";
    @Override
    public void getGouWuCheData(String url, Map<String, String> map, final GouWuCheListener gouWuCheListener) {
        HttpUtils httpUtils = HttpUtils.getHttpUtils();
        httpUtils.okPost(url, map);
        httpUtils.setOkLoadListener(new OkLoadListener() {
            @Override
            public void okLoadSuccess(String json) {
                Log.d(TAG, "okLoadSuccess: "+json);
                gouWuCheListener.getDataSuccess(json);
            }

            @Override
            public void okLoadError(String error) {
                Log.d(TAG, "okLoadError: "+error);
                gouWuCheListener.getDataError(error);
            }
        });
    }

    @Override
    public void jisuan(List<GouWuBean.DataBean> list, JiSuanListener jiSuanListener) {
        double sum = 0;
        for (int i = 0; i < list.size(); i++) {
            List<GouWuBean.ChildBean> list_child = list.get(i).getList();
            for (int j = 0; j < list_child.size(); j++) {
                boolean child_flag = list_child.get(j).isChild_flag();
                if (child_flag){
                    double price = list_child.get(j).getPrice();
                    sum+=price;
                }

            }
        }
        //记得回调
        jiSuanListener.jiSuan(sum);
    }
}
//GouWuCheListener购物车监听
package com.daydayup.day14_gouwuche.model;

/**
 * Created by gjl on 2018/4/25.
 */

public interface GouWuCheListener {
    void getDataSuccess(String json);
    void getDataError(String error);
}
//JiSuanListener计算监听
package com.daydayup.day14_gouwuche.model;

/**
 * Created by gjl on 2018/4/26.
 */

public interface JiSuanListener {
    void jiSuan(double price);
}
//PresenterImpl
//IPresenter
package com.daydayup.day14_gouwuche.presenter;

import com.daydayup.day14_gouwuche.model.IModel;
import com.daydayup.day14_gouwuche.view.IMainView;

/**
 * Created by gjl on 2018/4/25.
 */

public interface IPresenter {
    void showGouWuCheToView(IModel iModel, IMainView iMainView);
    //将计算结果显示到view
    void showSumToView(IModel iModel, IMainView iMainView);
}
//PresenterImpl
package com.daydayup.day14_gouwuche.presenter;

import android.util.Log;

import com.daydayup.day14_gouwuche.http.HttpConfig;
import com.daydayup.day14_gouwuche.model.GouWuBean;
import com.daydayup.day14_gouwuche.model.GouWuCheListener;
import com.daydayup.day14_gouwuche.model.IModel;
import com.daydayup.day14_gouwuche.model.JiSuanListener;
import com.daydayup.day14_gouwuche.view.IMainView;
import com.google.gson.Gson;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by gjl on 2018/4/25.
 */

public class PresenterImpl implements IPresenter {
    private static final String TAG = "PresenterImpl----";

    //显示数据
    @Override
    public void showGouWuCheToView(IModel iModel, final IMainView iMainView) {
        Map<String, String> map = new HashMap<>();
        map.put("uid", "71");
        iModel.getGouWuCheData(HttpConfig.gouwuche_url, map, new GouWuCheListener() {

            @Override
            public void getDataSuccess(String json) {
                Gson gson = new Gson();
                GouWuBean gouWuBean = gson.fromJson(json, GouWuBean.class);
                List<GouWuBean.DataBean> list = gouWuBean.getData();
                //传入view
                iMainView.showGowWuList(list);
            }

            @Override
            public void getDataError(String error) {
                Log.d(TAG, "error: " + error);
            }
        });
    }
    //显示计算结果
    @Override
    public void showSumToView(IModel iModel, final IMainView iMainView) {
        iModel.jisuan(iMainView.getList(), new JiSuanListener() {
            @Override
            public void jiSuan(double price) {
                iMainView.showSum(price);
            }
        });
    }
}
//View
//IMainView
package com.daydayup.day14_gouwuche.view;

import com.daydayup.day14_gouwuche.model.GouWuBean;

import java.util.List;

/**
 * View接口
 */

public interface IMainView {
    //显示数据
    void showGowWuList(List<GouWuBean.DataBean> list);
    //显示总价
    void showSum(double price);
    //获取集合数据
    List<GouWuBean.DataBean> getList();
}
//MainActivity
package com.daydayup.day14_gouwuche.view;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ExpandableListView;
import android.widget.TextView;
import android.widget.Toast;

import com.daydayup.day14_gouwuche.R;
import com.daydayup.day14_gouwuche.adapters.MyAdapter;
import com.daydayup.day14_gouwuche.model.GouWuBean;
import com.daydayup.day14_gouwuche.model.ModelImpl;
import com.daydayup.day14_gouwuche.presenter.PresenterImpl;

import java.util.List;

public class MainActivity extends AppCompatActivity implements View.OnClickListener,IMainView {

    private ExpandableListView expandableListView;
    private CheckBox checkBox;
    private TextView tv_sum;
    private Button jisuan;
    private static final String TAG = "MainActivity0------";
    private List<GouWuBean.DataBean> list_tmp;
    private MyAdapter myAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //初始化控件
        initViews();
        //请求数据
        initDatas();
    }

    private void initDatas() {
        PresenterImpl presenter = new PresenterImpl();
        presenter.showGouWuCheToView(new ModelImpl(),this);
    }

    private void initViews() {
        expandableListView = findViewById(R.id.expandable_list_view);
        checkBox = findViewById(R.id.cb);
        tv_sum = findViewById(R.id.tv_sum);
        jisuan = findViewById(R.id.jisuan);

        checkBox.setOnClickListener(this);
        jisuan.setOnClickListener(this);
    }

    //点击事件
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            //全选,全部选  总价
            case R.id.cb:
                boolean checked = checkBox.isChecked();
                for (int i = 0; i < list_tmp.size(); i++) {
                    list_tmp.get(i).setParent_flag(checked);
                    List<GouWuBean.ChildBean> list_child = list_tmp.get(i).getList();
                    for (int j = 0; j < list_child.size(); j++) {

                        list_child.get(j).setChild_flag(checked);
                    }
                }
                //刷新适配器
                myAdapter.notifyDataSetChanged();
                //调用计算总价的方法
                PresenterImpl presenter = new PresenterImpl();
                presenter.showSumToView(new ModelImpl(),this);
                break;

            case R.id.jisuan:
                Toast.makeText(MainActivity.this,"去计算总价",Toast.LENGTH_SHORT).show();
                break;
        }
    }
    //展示购物车数据
    @Override
    public void showGowWuList(List<GouWuBean.DataBean> list) {
        list_tmp=list;
        Log.d(TAG, "showGowWuList: "+list);

        myAdapter = new MyAdapter(MainActivity.this, list,this);
        expandableListView.setAdapter(myAdapter);
        //展开expandablelistview
        int childCount = expandableListView.getCount();
        for (int i = 0; i < childCount; i++) {
            expandableListView.expandGroup(i);
        }
    }
    //显示总价
    @Override
    public void showSum(double price) {
        tv_sum.setText("合计:"+price);
    }

    @Override
    public List<GouWuBean.DataBean> getList() {
        return list_tmp;
    }
}
//custumviews自定义GV
/AddSubView
package com.daydayup.day14_gouwuche.view.custumviews;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.daydayup.day14_gouwuche.R;

/**
 * Created by gjl on 2018/4/26.
 */

public class AddSubView extends LinearLayout implements View.OnClickListener {

    private TextView add;
    private TextView sub;
    private EditText count;

    public AddSubView(Context context) {
        this(context, null);
    }

    public AddSubView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public AddSubView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        View view = View.inflate(context, R.layout.add_layout, this);
        add = view.findViewById(R.id.add);
        sub = view.findViewById(R.id.sub);

        add.setOnClickListener(this);
        sub.setOnClickListener(this);
        count = view.findViewById(R.id.count);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.add:
                add();
                break;

            case R.id.sub:
                sub();
                break;
        }
    }

    //添加
    public void add() {
        String s = count.getText().toString();
        double i = Double.parseDouble(s);
        i++;
        count.setText(i + "");
    }

    //减少
    public void sub() {
        String s = count.getText().toString();
        double i = Double.parseDouble(s);
        if (i >= 1) {
            i--;
            count.setText(i + "");
        }

    }
    //设置数量

    //获取数量
    public String getCount() {
        return count.getText().toString();
    }

    public void setCount(double count1){
        count.setText(count1+"");
    }

}
//BeanUtils
//GouWuBean
package com.daydayup.day14_gouwuche.model;

import java.util.List;

/**
 * Created by gjl on 2018/4/25.
 */

public class GouWuBean {

    /**
     * msg : 请求成功
     * code : 0
     * data : [{"list":[],"sellerName":"","sellerid":"0"},{"list":[{"bargainPrice":11800,"createtime":"2017-10-10T17:33:37","detailUrl":"https://item.m.jd.com/product/4338107.htmlChildBeanutm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t6700/155/2098998076/156185/6cf95035/595dd5a5Nc3a7dab5.jpg!q70.jpg","num":2,"pid":57,"price":5199,"pscid":40,"selected":0,"sellerid":1,"subhead":"【i5 MX150 2G显存】全高清窄边框 8G内存 256固态硬盘 支持指纹识别 预装WIN10系统","title":"小米(MI)Air 13.3英寸全金属轻薄笔记本(i5-7200U 8G 256G PCle SSD MX150 2G独显 FHD 指纹识别 Win10)银 "}],"sellerName":"商家1","sellerid":"1"},{"list":[{"bargainPrice":3455,"createtime":"2017-10-03T23:53:28","detailUrl":"https://item.m.jd.com/product/12224420750.htmlChildBeanutm_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":5,"pid":54,"price":888,"pscid":39,"selected":0,"sellerid":10,"subhead":"【现货新品抢购】全面屏2.0震撼来袭,骁龙835处理器,四曲面陶瓷机","title":"小米(MI) 小米MIX2 手机 黑色 全网通 (6GB+64GB)【标配版】"}],"sellerName":"商家10","sellerid":"10"},{"list":[{"bargainPrice":3455,"createtime":"2017-10-14T21:38:26","detailUrl":"https://item.m.jd.com/product/12224420750.htmlChildBeanutm_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":56,"price":99,"pscid":39,"selected":0,"sellerid":12,"subhead":"【现货新品抢购】全面屏2.0震撼来袭,骁龙835处理器,四曲面陶瓷机","title":"小米(MI) 小米MIX2 手机 黑色 全网通 (6GB+64GB)【标配版】"},{"bargainPrice":11800,"createtime":"2017-10-14T21:48:08","detailUrl":"https://mitem.jd.hk/ware/view.actionChildBeanwareId=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":68,"price":15000,"pscid":40,"selected":0,"sellerid":12,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"}],"sellerName":"商家12","sellerid":"12"}]
     */

    private String msg;
    private String code;
    private List<DataBean> data;

    public String getMsg() {
        return msg;
    }

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

    public String getCode() {
        return code;
    }

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

    public List<DataBean> getData() {
        return data;
    }

    public void setData(List<DataBean> data) {
        this.data = data;
    }
    //商家
    public static class DataBean {
        /**
         * list : []
         * sellerName :
         * sellerid : 0
         */

        private String sellerName;
        private String sellerid;
        private List<ChildBean> list;
        //状态
        private boolean parent_flag;

        public boolean isParent_flag() {
            return parent_flag;
        }

        public void setParent_flag(boolean parent_flag) {
            this.parent_flag = parent_flag;
        }

        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<ChildBean> getList() {
            return list;
        }

        public void setList(List<ChildBean> list) {
            this.list = list;
        }
    }
    public class ChildBean{

        /**
         * bargainPrice : 11800
         * createtime : 2017-10-10T17:33:37
         * detailUrl : https://item.m.jd.com/product/4338107.htmlChildBeanutm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends
         * images : https://m.360buyimg.com/n0/jfs/t6700/155/2098998076/156185/6cf95035/595dd5a5Nc3a7dab5.jpg!q70.jpg
         * num : 2
         * pid : 57
         * price : 5199
         * pscid : 40
         * selected : 0
         * sellerid : 1
         * subhead : 【i5 MX150 2G显存】全高清窄边框 8G内存 256固态硬盘 支持指纹识别 预装WIN10系统
         * title : 小米(MI)Air 13.3英寸全金属轻薄笔记本(i5-7200U 8G 256G PCle SSD MX150 2G独显 FHD 指纹识别 Win10)银
         */

        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;

        //是否选中的状态
        private boolean child_flag;

        public boolean isChild_flag() {
            return child_flag;
        }

        public void setChild_flag(boolean child_flag) {
            this.child_flag = child_flag;
        }

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
















Android - 购物车页面【仿】淘宝App 首先是效果图 xml布局文件 activity_shopping.xml "http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <RelativeLayout 阅读详情

相关推荐

Android 购物车实现(思路+步骤+源码,android视频提取音频

面试是一个不断学习、不断自我提升的过程,有机会还是出去面面,至少能想到查漏补缺效果,而且有些知识点,可能你自以为知道,但让你说,并不一定能说得很好。有些东西有压力才有动力,而学到的知识点,都是钱(因为技术人员大部分情况是根据你的能力来定级、来发薪水的),技多不压身。附上我的面试各大专题整理: 面试指南,满满的都是干货,希望对大家有帮助!本文已被CODING开源项目:《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》收录一个人可以走的很快,但一群人才能走的更远。

2401_83620927的博客 2799

Android -- 购物车

Android的简单购物车案例

十二间记,知不足而奋斗,望远山而前行。千里不辞行路远,时光早晚到天涯。 9526

Android实现商城购物车功能的实例代码

最近公司项目做商城模块,需要实现购物车功能,主要实现了单选、全选,金额合计,商品删除,商品数量加减等功能,这篇文章主要介绍了Android实现商城购物车功能,需要的朋友可以参考下

Android商城购物车页面实现

公司有个项目需要做购物车功能,于是实现了一下,另加了个浮动title ,侧滑删除,示例图片如下     //侧滑删除 compile 'com.github.anzaizai:EasySwipeMenuLayout:1.1.2' 实现方式   adapter用的是封装的 CommonAdapter 代码如下 package com.loocan.shpping.viewho...

loocanp的博客 1万+

Android仿外卖购物车功能

先看看效果图: 知识点分析 效果图来看不复杂内容并没多少,值得介绍一下的知识点也就下面几个吧 – 列表标题悬停 – 左右列表滑动时联动 – 添加商品时的抛物线动画 – 底部弹出购物车清单 – 数据的同步 另外就是实现效果的时候可能会遇到的几个坑。。。 布局很简单直接进入代码 1:列表标题悬停 现在做项目列表什么的基本抛弃了ListView改用RecyclerView,上篇博客中的标题悬停也是使用了一个RecyclerView的开源项目sticky-headers-recyclerview,不过写这个demo的时候遇到了两个坑 1)、sticky-headers-recyclervi

Ubuntu系统下主板GPU温控pwm风扇

在Linux系统下——以Ubuntu为例,配置主板sys_fan等接口连接pwm温控风扇转速根据NVIDIA GPU温度,为服务器GPU等无主动散热显卡提供散热。

罗思哲的博客 5034

MVP,购物车啊,图片加载用Fresco,OKhttp+Retrofit实现

1.项目框架:MVP(评分重点),图片加载用Fresco,网络请求用OKhttp+Retrofit实现(自己封装,加单例模式,(评分重点)), 2.完成购物车数据添加(如果接口无数据,可用接口工具添加数据), 3.自定义view实现加减按钮,每次点击加减,item中的总数及总价要做出相应的改变。 4.当数量为1时,点击减号,数量不变,吐司提示用户最小数量为1。 5.底部总数及总价为所有it

xxb52306的博客 475

Springer期刊LaTeX模板中参考文献格式选择与编译错误的快速修复指南

本文针对Springer期刊LaTeX模板中参考文献编译后显示问号的常见问题,提供了快速修复指南。核心在于正确选择并配置与期刊匹配的参考文献格式文件(.bst),并执行标准的四步编译流程。文章详细解释了问题根源,并给出了从查找正确.bst文件到修改代码、执行编译的完整解决方案,帮助作者高效解决投稿中的技术障碍。

weixin_29266007的博客 402

购物车+MVP+图片加载Fresco +OKhttp+Retrofit默认全选+删除

说明 MVP,图片加载Fresco,网络请求用OKhttp+Retrofit, 完成购物车数据添加 自定义view实现加减按钮,每次点击加减,item中的总数及总价要做出相应的改变。 当数量为1时,点击减号,数量不变,吐司提示用户最小数量为1。 底部总数总价为所有item项中的总价及总数,每个item中数量价格的更改,底部总价总数要与之联动 单选反选全选功能,首次进入默认全选,it

blgktlp的博客 406

一起学习Avalonia(十三)

Avalonia 前面已经简单介绍了一下相关开发,有一个系统的了解。 到今天Avalonia已经基本成熟,但是扩展支持的还是不可能达到大企业的,我估计这也不可能。考虑了下,微软的MAUI框架可能会普及性更高,Avalonia也是我无意间知道的。 微软毕竟是会宣讲的全球。并且微软全球研发投入很大,全部专职开发,这种速度当然大。但是MAUI根据计划,可能还要很长时间,而且是社区支持Linux,估计时间更久。这不能适应现在的国产化开发。 预计一段时间还是需要Avalonia作为优先。当前Avalonia使

jinyuttt的专栏 4086

1、微软 Intune 全面指南:配置、管理与自动化

本文全面介绍了微软 Intune 的配置、管理和自动化操作,涵盖用户与设备管理、安全策略设置、跨平台应用部署、合规性监控及报告分析等内容。通过详细的操作步骤、自动化脚本示例和流程优化建议,帮助技术人员高效掌握 Intune 在混合办公环境中的实际应用,并展望其未来发展趋势。

ii567的博客 361

购物车okhttp++mvp-------lll

请求网络的权限&lt;uses-permission android:name="android.permission.INTERNET"/&gt; 依赖compile 'com.squareup.okhttp3:okhttp:3.10.0' compile 'com.google.code.gson:gson:2.2.4' compile 'com.github.bumptech.glide:...

love_xxxooo的博客 455

WPF+MVVM案例实战(二十三)- 阴影效果详解

通过附加属性实现阴影效果,通过改变不同的阴影属性值达到不同阴影效果

lingshuangcanxue 561

OkHttp+listview+MVP购物车

依赖:compile 'com.google.code.gson:gson:2.2.4' compile 'com.github.bumptech.glide:glide:3.7.0' compile 'com.squareup.okhttp3:okhttp:3.10.0'权限: uses-permission android:name="android.permission.INTERNET"

Lucky_7777777的博客 440

科研绘图系列:R语言绘制世界地图数据分布(world map)

科研绘图系列:R语言绘制世界地图数据分布(world map)

专注生信领域 527

一篇文章足够你学习Bluez,提供史上最全的Bluez教程,让你告别Bluez从入门到放弃

Bluez是真的难,说“入门到放弃”真的毫不夸张,Bluez的学习曲线陡峭,要求对Linux 系统/驱动概念、D-Bus 通信和蓝牙协议都有要求,加上网络上其实没有一个完整的介绍Bluez系列的文档,所以不管是蓝牙初学者还是蓝牙从业人员,都有不小的难度。

朝气蓬勃 2539

使用MVP,recycleview,okhttp生成二级购物车。

一,根据要求添加依赖,权限工具。       1,加入依赖。              compile files('libs/gson-2.2.4.jar') compile files('libs/universal-image-loader-1.9.3-with-sources.jar') compile 'com.android.support:recyclerview-v7:26

weixin_39586678的博客 492

太阳敏感器:卫星姿态控制的“指南针

在卫星姿态控制系统中,太阳敏感器(Sun Sensor) 是至关重要的光学姿态敏感器之一。它通过探测太阳光的方向,为卫星提供关键的姿态参考信息,确保卫星能够正确调整自身方位,维持稳定的对日定向,保障能源供应和任务执行。

ScilogyHunter的博客 1731

购物车简单MVP构建及okhttp

**使用接口:**http://120.27.23.105/product/getCarts?uid=100 导入依赖: //okHttp依赖 implementation 'com.squareup.okhttp3:okhttp:3.11.0' implementation 'com.squareup.okhttp3:logging-interceptor:3.11.0' ...

qq_43580899的博客 233

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

MVP实现购物车(二级列表),删除结算功能,拦截器+封装okHttp

图片依赖 compile 'com.squareup.okhttp3:okhttp:3.9.1' compile 'com.google.code.gson:gson:2.8.+' compile 'com.github.bumptech.glide:glide:3.6.1'权限<uses-permission android:name="android.permission.

酒醉奈何橋 811

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

okhttp+retrofit+fresco+mvp实现购物车

依赖 //添加retrofit依赖 compile 'com.squareup.retrofit2:retrofit:2.3.0' //添加gson转换器的依赖 compile 'com.squareup.retrofit2:converter-gson:2.3.0' //RXJava的依赖 compile "io.reactivex.rxjava2:rxj

xiaozi_11的博客 438

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

Mvp+OkHttp+购物车

MyCallBack public interface MyCallBack { void setData(Data data); void setError(String error); } Model public interface Model { void getData(String url, MyCallBack callBack); } pub...

chengronglri的博客 274

retrofit+rxjava + okhttp +mvp 购物车

分包的情况 1. 依赖//添加retrofit依赖 compile ‘com.squareup.retrofit2:retrofit:2.3.0’ //添加gson转换器的依赖 compile ‘com.squareup.retrofit2:converter-gson:2.3.0’ //RXJava的依赖 compile “io.reactive

Mymiak的博客 2442

MVP+Fresco+OKhttp+Retrofit实现购物车

所需依赖: compile 'com.squareup.retrofit2:retrofit:2.3.0' compile 'com.squareup.retrofit2:converter-gson:2.3.0' compile 'io.reactivex.rxjava2:rxjava:2.1.7' compile 'com.squareup.retrofit2:adapter-rxjav

Mr_WangXiao123的博客 702

android购物车二级列表实现+MVP+Okhttp

//主界面 package com.example.shop; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.support.v7.app.AppCompatActivity; import android.view.View; import an

qq_40072398的博客 459
上一篇: Fenglei
下一篇: mvp+okhttp注册登录
Androidoux98
博客等级 码龄9年 3粉丝 40原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值