详情跳转到购物车

> 依赖

 

```

compile 'com.android.support:appcompat-v7:26.+'

compile 'com.android.support.constraint:constraint-layout:1.0.2'

compile 'io.reactivex.rxjava2:rxjava:2.0.7'

compile 'io.reactivex.rxjava2:rxandroid:2.0.1'

compile 'com.squareup.retrofit2:retrofit:2.1.0'

compile 'com.squareup.retrofit2:adapter-rxjava2:2.2.0'

compile 'com.squareup.retrofit2:converter-gson:2.1.0'

compile 'com.squareup.retrofit2:converter-scalars:2.1.0'

compile 'com.jakewharton:butterknife:8.8.1'

compile 'com.android.support:recyclerview-v7:26.0.0-alpha1'

compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'

compile 'com.facebook.fresco:fresco:0.12.0'

compile 'com.github.bumptech.glide:glide:3.7.0'

compile 'org.greenrobot:eventbus:3.1.1'

compile 'com.android.support:design:26.0.0-alpha1'

compile 'com.dou361.ijkplayer:jjdxm-ijkplayer:1.0.5'

testCompile 'junit:junit:4.12'

annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'

```

 

> 权限

 

```

<uses-permission android:name="android.permission.INTERNET" />

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

```

 

Utils

=====

 

> DownLoadFile

--------------

 

```

public class DownLoadFile {

    private static final String SP_NAME = "download_file";  

    private static final String CURR_LENGTH = "curr_length";  

    private static final int DEFAULT_THREAD_COUNT = 4;//默认下载线程数  

    //以下为线程状态  

    private static final String DOWNLOAD_INIT = "1";  

    private static final String DOWNLOAD_ING = "2";  

    private static final String DOWNLOAD_PAUSE = "3";  

  

    private Context mContext;

  

    private String loadUrl;//网络获取的url  

    private String filePath;//下载到本地的path  

    private int threadCount = DEFAULT_THREAD_COUNT;//下载线程数  

  

    private int fileLength;//文件总大小  

    //使用volatile防止多线程不安全  

    private volatile int currLength;//当前总共下载的大小  

    private volatile int runningThreadCount;//正在运行的线程数  

    private Thread[] mThreads;  

    private String stateDownload = DOWNLOAD_INIT;//当前线程状态  

  

    private DownLoadListener mDownLoadListener;  

  

    public void setOnDownLoadListener(DownLoadListener mDownLoadListener) {  

        this.mDownLoadListener = mDownLoadListener;  

    }  

  

    public interface DownLoadListener {

        //返回当前下载进度的百分比  

        void getProgress(int progress);  

  

        void onComplete();  

  

        void onFailure();  

    }  

  

    public DownLoadFile(Context mContext, String loadUrl, String filePath) {  

        this(mContext, loadUrl, filePath, DEFAULT_THREAD_COUNT, null);  

    }  

  

    public DownLoadFile(Context mContext, String loadUrl, String filePath, DownLoadListener mDownLoadListener) {  

        this(mContext, loadUrl, filePath, DEFAULT_THREAD_COUNT, mDownLoadListener);  

    }  

  

    public DownLoadFile(Context mContext, String loadUrl, String filePath, int threadCount) {  

        this(mContext, loadUrl, filePath, threadCount, null);  

    }  

  

    public DownLoadFile(Context mContext, String loadUrl, String filePath, int threadCount, DownLoadListener mDownLoadListener) {  

        this.mContext = mContext;  

        this.loadUrl = loadUrl;  

        this.filePath = filePath;  

        this.threadCount = threadCount;  

        runningThreadCount = 0;  

        this.mDownLoadListener = mDownLoadListener;  

    }  

  

    /**

     * 开始下载

     */

    public void downLoad() {

        //在线程中运行,防止anr  

        new Thread(new Runnable() {  

            @Override  

            public void run() {  

                try {  

                    //初始化数据  

                    if (mThreads == null)  

                        mThreads = new Thread[threadCount];  

  

                    //建立连接请求  

                    URL url = new URL(loadUrl);

                    HttpURLConnection conn = (HttpURLConnection) url.openConnection();

                    conn.setConnectTimeout(5000);  

                    conn.setRequestMethod("GET");  

                    int code = conn.getResponseCode();//获取返回码  

                    if (code == 200) {//请求成功,根据文件大小开始分多线程下载  

                        fileLength = conn.getContentLength();  

                        //根据文件大小,先创建一个空文件  

                        //“r“——以只读方式打开。调用结果对象的任何 write 方法都将导致抛出 IOException。  

                        //“rw“——打开以便读取和写入。如果该文件尚不存在,则尝试创建该文件。  

                        //“rws“—— 打开以便读取和写入,对于 “rw”,还要求对文件的内容或元数据的每个更新都同步写入到底层存储设备。  

                        //“rwd“——打开以便读取和写入,对于 “rw”,还要求对文件内容的每个更新都同步写入到底层存储设备。  

                        RandomAccessFile raf = new RandomAccessFile(filePath, "rwd");

                        raf.setLength(fileLength);  

                        raf.close();  

                        //计算各个线程下载的数据段  

                        int blockLength = fileLength / threadCount;  

  

                        SharedPreferences sp = mContext.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);

                        //获取上次取消下载的进度,若没有则返回0  

                        currLength = sp.getInt(CURR_LENGTH, 0);  

                        for (int i = 0; i < threadCount; i++) {  

                            //开始位置,获取上次取消下载的进度,默认返回i*blockLength,即第i个线程开始下载的位置  

                            int startPosition = sp.getInt(SP_NAME + (i + 1), i * blockLength);  

                            //结束位置,-1是为了防止上一个线程和下一个线程重复下载衔接处数据  

                            int endPosition = (i + 1) * blockLength - 1;  

                            //将最后一个线程结束位置扩大,防止文件下载不完全,大了不影响,小了文件失效  

                            if ((i + 1) == threadCount)  

                                endPosition = endPosition * 2;  

  

                            mThreads[i] = new DownThread(i + 1, startPosition, endPosition);  

                            mThreads[i].start();  

                        }  

                    }else {  

                        handler.sendEmptyMessage(FAILURE);  

                    }  

                } catch (Exception e) {  

                    e.printStackTrace();  

                    handler.sendEmptyMessage(FAILURE);  

                }  

            }  

        }).start();  

    }  

  

    /**

     * 取消下载

     */  

    protected void cancel() {  

        if (mThreads != null) {  

            //若线程处于等待状态,则while循环处于阻塞状态,无法跳出循环,必须先唤醒线程,才能执行取消任务  

            if (stateDownload.equals(DOWNLOAD_PAUSE))  

                onStart();  

            for (Thread dt : mThreads) {  

                ((DownThread) dt).cancel();  

            }  

        }  

    }  

  

    /**

     * 暂停下载

     */

    public void onPause() {

        if (mThreads != null)  

            stateDownload = DOWNLOAD_PAUSE;  

    }  

  

    /**

     * 继续下载

     */

    public void onStart() {

        if (mThreads != null)  

            synchronized (DOWNLOAD_PAUSE) {  

                stateDownload = DOWNLOAD_ING;  

                DOWNLOAD_PAUSE.notifyAll();  

            }  

    }  

  

    public void onDestroy() {

        if (mThreads != null)  

            mThreads = null;  

    }  

  

    private class DownThread extends Thread {  

  

        private boolean isGoOn = true;//是否继续下载  

        private int threadId;  

        private int startPosition;//开始下载点  

        private int endPosition;//结束下载点  

        private int currPosition;//当前线程的下载进度  

  

        private DownThread(int threadId, int startPosition, int endPosition) {  

            this.threadId = threadId;  

            this.startPosition = startPosition;  

            currPosition = startPosition;  

            this.endPosition = endPosition;  

            runningThreadCount++;  

        }  

  

        @Override  

        public void run() {  

            SharedPreferences sp = mContext.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);  

            try {  

                URL url = new URL(loadUrl);  

                HttpURLConnection conn = (HttpURLConnection) url.openConnection();  

                conn.setRequestMethod("GET");  

                conn.setRequestProperty("Range", "bytes=" + startPosition + "-" + endPosition);  

                conn.setConnectTimeout(5000);  

                //若请求头加上Range这个参数,则返回状态码为206,而不是200  

                if (conn.getResponseCode() == 206) {  

                    InputStream is = conn.getInputStream();

                    RandomAccessFile raf = new RandomAccessFile(filePath, "rwd");  

                    raf.seek(startPosition);//跳到指定位置开始写数据  

                    int len;  

                    byte[] buffer = new byte[1024];  

                    while ((len = is.read(buffer)) != -1) {  

                        //是否继续下载  

                        if (!isGoOn)  

                            break;  

                        //回调当前进度  

                        if (mDownLoadListener != null) {  

                            currLength += len;  

                            int progress = (int) ((float) currLength / (float) fileLength * 100);  

                            handler.sendEmptyMessage(progress);  

                        }  

  

                        raf.write(buffer, 0, len);  

                        //写完后将当前指针后移,为取消下载时保存当前进度做准备  

                        currPosition += len;  

                        synchronized (DOWNLOAD_PAUSE) {  

                            if (stateDownload.equals(DOWNLOAD_PAUSE)) {  

                                DOWNLOAD_PAUSE.wait();  

                            }  

                        }  

                    }  

                    is.close();  

                    raf.close();  

                    //线程计数器-1  

                    runningThreadCount--;  

                    //若取消下载,则直接返回  

                    if (!isGoOn) {  

                        //此处采用SharedPreferences保存每个线程的当前进度,和三个线程的总下载进度  

                        if (currPosition < endPosition) {  

                            sp.edit().putInt(SP_NAME + threadId, currPosition).apply();  

                            sp.edit().putInt(CURR_LENGTH, currLength).apply();  

                        }  

                        return;  

                    }  

                    if (runningThreadCount == 0) {  

                        sp.edit().clear().apply();  

                        handler.sendEmptyMessage(SUCCESS);  

                        handler.sendEmptyMessage(100);  

                        mThreads = null;  

                    }  

                } else {  

                    sp.edit().clear().apply();  

                    handler.sendEmptyMessage(FAILURE);  

                }  

            } catch (Exception e) {  

                sp.edit().clear().apply();  

                e.printStackTrace();  

                handler.sendEmptyMessage(FAILURE);  

            }  

        }  

  

        public void cancel() {  

            isGoOn = false;  

        }  

    }  

  

    private final int SUCCESS = 0x00000101;  

    private final int FAILURE = 0x00000102;  

  

    private Handler handler = new Handler() {

        @Override  

        public void handleMessage(Message msg) {

  

            if (mDownLoadListener != null) {  

                if (msg.what == SUCCESS) {  

                    mDownLoadListener.onComplete();  

                } else if (msg.what == FAILURE) {  

  

                    mDownLoadListener.onFailure();  

                } else {  

                    mDownLoadListener.getProgress(msg.what);  

                }  

            }  

        }  

    };  

}  

```

 

> MyApp

-------

 

```

 

public class MyApp extends Application {

    @Override

    public void onCreate() {

        super.onCreate();

        //配置磁盘缓存

        DiskCacheConfig diskSmallCacheConfig = DiskCacheConfig.newBuilder(this)

                .setBaseDirectoryPath(this.getCacheDir())//缓存图片基路径

                .setBaseDirectoryName(getString(R.string.app_name))//文件夹名

                .build();

        ImagePipelineConfig imagePipelineConfig = ImagePipelineConfig.newBuilder(this)

                .setBitmapsConfig(Bitmap.Config.RGB_565)

                .setSmallImageDiskCacheConfig(diskSmallCacheConfig)

                .build();

        //初始化Fresco

        Fresco.initialize(this, imagePipelineConfig);

    }

}

 

```

 

net

===

 

> ServiceApi

------------

 

```

public interface ServiceApi {

    //商品详情

    @GET(Urls.PRODUCTDETAIL)

    Observable<ProductDetailBean> getDetail(@Query("pid") String pid);

 

    //添加购物车

    @GET(Urls.ADDCART)

    Observable<AddCartBean> addCart(@Query("pid") String pid, @Query("uid") String uid);

 

    //查询购物车

    @GET(Urls.GETCARTS)

    Observable<CartBean> getCarts(@Query("uid") String uid);

 

}

```

 

> OnNetListener

---------------

 

```

public interface OnNetListener<T> {

    public void onSuccess(T t);

 

    public void onFailure(Throwable throwable);

}

```

 

> RetrofitHelper

----------------

 

```

public class RetrofitHelper {

    private static OkHttpClient okHttpClient;

    private static ServiceApi serviceApi;

 

    static {

        initOkHttpClient();

    }

 

    /**

     * 创建OkHttpClient

     */

    private static void initOkHttpClient() {

        if (okHttpClient == null) {

            synchronized (RetrofitHelper.class) {

                if (okHttpClient == null) {

                    //设置拦截器

                    HttpLoggingInterceptor logging = new HttpLoggingInterceptor();

                    logging.setLevel(HttpLoggingInterceptor.Level.BODY);

                    okHttpClient = new OkHttpClient.Builder()

                            .addInterceptor(logging)//添加拦截器

                            .addInterceptor(new MyInterceptor())

                            .connectTimeout(5, TimeUnit.SECONDS)//设置连接超时

                            .build();

                }

            }

        }

    }

 

    /**

     * 定义一个泛型方法

     *

     * @param tClass

     * @param url

     * @param <T>

     * @return

     */

    public static <T> T createAPi(Class<T> tClass, String url) {

        Retrofit retrofit = new Retrofit.Builder()

                .baseUrl(url)

                .client(okHttpClient)

                .addConverterFactory(GsonConverterFactory.create())

                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())

                .build();

        return retrofit.create(tClass);

    }

 

    /**

     * 初始化ServiceApi

     *

     * @return

     */

    public static ServiceApi getServiceApi() {

        if (serviceApi == null) {

            synchronized (ServiceApi.class) {

                if (serviceApi == null) {

                    serviceApi = createAPi(ServiceApi.class, Urls.BASE_URL);

                }

            }

        }

        return serviceApi;

    }

 

    /**

     * 添加公共参数拦截器

     */

    static class MyInterceptor implements Interceptor {

 

        @Override

        public Response intercept(Chain chain) throws IOException {

            Request request = chain.request();

            HttpUrl httpUrl = request.url()

                    .newBuilder()

                    .addQueryParameter("source", "android")

                    .build();

            Request build = request.newBuilder()

                    .url(httpUrl)

                    .build();

            return chain.proceed(build);

        }

    }

}

 

```

 

> Urls

-----

 

```

public class Urls {

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

    //详情

    public static final String PRODUCTDETAIL = "product/getProductDetail";

    //添加购物车

    public static final String ADDCART = "product/addCart";

    //查询购物车

    public static final String GETCARTS = "product/getCarts";

}

 

```

 

View层

=====

 

> MainActivity

--------------

 

```

public class MainActivity extends AppCompatActivity implements View.OnClickListener{

    /**

     * 下载

     */

    private Button mBtXiazai;

    /**

     * 暂停

     */

    private Button mBtZanting;

    /**

     * 继续

     */

    private Button mBtJixu;

    private ProgressBar mPro;

    /**

     * 下载:0%

     */

    private TextView mTvProgress;

    /**

     * 进入详情

     */

    private Button mBtXiangqing;

    private DownLoadFile downLoadFile;

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        initView();

    }

    private void initView() {

        mBtXiazai = (Button) findViewById(R.id.bt_xiazai);

        mBtXiazai.setOnClickListener(this);

        mBtZanting = (Button) findViewById(R.id.bt_zanting);

        mBtZanting.setOnClickListener(this);

        mBtJixu = (Button) findViewById(R.id.bt_jixu);

        mBtJixu.setOnClickListener(this);

        mPro = (ProgressBar) findViewById(R.id.pro);

        mTvProgress = (TextView) findViewById(R.id.tv_progress);

        mBtXiangqing = (Button) findViewById(R.id.bt_xiangqing);

        mBtXiangqing.setOnClickListener(this);

        File f = new File(Environment.getExternalStorageDirectory() + "/wenjian/");

        if (!f.exists()) {

            f.mkdir();

        }

        //存储地址

        String path = Environment.getExternalStorageDirectory() + "/wenjian/ww.mp4";

        //设置最大度

        mPro.setMax(100);

        //实例化

        downLoadFile = new DownLoadFile(this,

                "http://mirror.aarnet.edu.au/pub/TED-talks/911Mothers_2010W-480p.mp4"

                , path, 10, new DownLoadFile.DownLoadListener() {

            @Override

            public void getProgress(int progress) {

                mTvProgress.setText("当前进度:" + progress + "%");

                mPro.setProgress(progress);

            }

 

            @Override

            public void onComplete() {

                Toast.makeText(MainActivity.this, "下载完成", Toast.LENGTH_SHORT).show();

            }

 

            @Override

            public void onFailure() {

                Toast.makeText(MainActivity.this, "下载失败", Toast.LENGTH_SHORT).show();

            }

        }

        );

    }

 

    @Override

    public void onClick(View v) {

        switch (v.getId()) {

            default:

                break;

            case R.id.bt_xiazai:

                downLoadFile.downLoad();

                break;

            case R.id.bt_zanting:

                downLoadFile.onPause();

                break;

            case R.id.bt_jixu:

                downLoadFile.onStart();

                break;

            case R.id.bt_xiangqing:

                Intent intent = new Intent(MainActivity.this, ProductDetailActivity.class);

                startActivity(intent);

                break;

        }

    }

 

    @Override

    protected void onDestroy() {

        super.onDestroy();

        downLoadFile.onDestroy();

    }

}

 

```

 

> CartActivity

--------------

 

```

public class CartActivity extends AppCompatActivity implements ICartView{

    private ExpandableListView mElv;

    private CheckBox mCbAll;

    /**

     * 全选

     */

    private TextView mTvQuxuan;

    /**

     * 合计 :¥550.90

     */

    private TextView mTvPrice;

    /**

     * 去支付(0)

     */

    private TextView mTvNum;

    private CartPresenter cartPresenter;

    private List<List<CartBean.DataBean.ListBean>> lists;

    private MyElvAdapter myElvAdapter;

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_cart);

        initView();

        //绑定EventBus

        EventBus.getDefault().register(this);

 

        cartPresenter = new CartPresenter(this);

        cartPresenter.getCart();

    }

    private void initView() {

        mElv = (ExpandableListView) findViewById(R.id.elv);

        mCbAll = (CheckBox) findViewById(R.id.cb_All);

        mTvQuxuan = (TextView) findViewById(R.id.tv_quxuan);

        mTvPrice = (TextView) findViewById(R.id.tv_price);

        mTvNum = (TextView) findViewById(R.id.tv_num);

        mTvNum.setOnClickListener(new View.OnClickListener() {

            @Override

            public void onClick(View v) {

                Intent intent = new Intent(CartActivity.this,DingGoodsActivity.class);

                startActivity(intent);

            }

        });

 

        //全选

        mCbAll.setOnClickListener(new View.OnClickListener() {

            @Override

            public void onClick(View v) {

                myElvAdapter.changeAllListCbState(mCbAll.isChecked());

            }

        });

    }

 

    @Override

    public void getCart(CartBean cartBean) {

        float price = 0;

        int num = 0;

 

        List<CartBean.DataBean> dataBeans = cartBean.getData();

        lists = new ArrayList<>();

        for (int i = 0; i < dataBeans.size(); i++) {

            List<CartBean.DataBean.ListBean> list = dataBeans.get(i).getList();

            lists.add(list);

        }

        //设置适配器

        myElvAdapter = new MyElvAdapter(this, dataBeans, lists);

        mElv.setAdapter(myElvAdapter);

        for (int i = 0; i < dataBeans.size(); i++) {

            //默认二级列表展开

            mElv.expandGroup(i);

        }

        //取消小箭头

        mElv.setGroupIndicator(null);

 

        //默认全选

        for (int i = 0; i < lists.size(); i++) {

            for (int j = 0; j < lists.get(i).size(); j++) {

                CartBean.DataBean.ListBean listBean = lists.get(i).get(j);

                price += listBean.getNum() * listBean.getPrice();

                num += listBean.getNum();

            }

        }

        mTvNum.setText(num);

        mTvPrice.setText(price + "");

    }

 

    @Subscribe

    public void onMessageEvent(MessageEvent event) {

        mCbAll.setChecked(event.isChecked());

    }

 

    @Subscribe

    public void onMessageEvent(PriceAndCountEvent event) {

        mTvPrice.setText("合计:¥" + event.getPrice() * event.getCount());

        mTvPrice.setText("总额:¥" + event.getPrice() * event.getCount());

        mTvNum.setText("去结算(" + event.getCount() + ")");

    }

 

 

    /**

     * 取消绑定,防止内存溢出

     */

    @Override

    protected void onDestroy() {

        super.onDestroy();

        //解除绑定

        EventBus.getDefault().unregister(this);

        cartPresenter.onDetach();

    }

}

 

```

 

> 接口

----

 

```

public interface ICartView {

    public void getCart(CartBean cartBean);

}

```

 

> ProductDetailActivity

-----------------------

 

```

 

public class ProductDetailActivity extends AppCompatActivity implements View.OnClickListener, IProductDetailView {

    private RecyclerView mXqRlv;

    private ImageView mIvGetcart;

    /**

     * 添加到购物车

     */

    private Button mBtAddcart;

    /**

     * 立即购买

     */

    private Button mBtTocart;

    private ProductDetailPresenter productDetailPresenter;

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_product_detail);

        initView();

        //设置布局管理器

        LinearLayoutManager layoutManager = new LinearLayoutManager(this);

        //加载线性布局

        mXqRlv.setLayoutManager(layoutManager);

 

        productDetailPresenter = new ProductDetailPresenter(this);

        productDetailPresenter.getProductDetail();

 

        /**

         * 播放视频

         */

        String path = Environment.getExternalStorageDirectory() + "/wenjian/ww.mp4";

        //String url = Environment.getExternalStorageDirectory()+ "/wenjian/ww.mp4";

        new PlayerView(this)

                .setTitle("视屏播放")

                .setScaleType(PlayStateParams.fitparent)

                .hideMenu(true)

                .forbidTouch(false)

                .setPlaySource(path)

                .startPlay();

    }

    private void initView() {

        mXqRlv = (RecyclerView) findViewById(R.id.xq_rlv);

        mIvGetcart = (ImageView) findViewById(R.id.iv_getcart);

        mBtAddcart = (Button) findViewById(R.id.bt_addcart);

        mBtAddcart.setOnClickListener(this);

        mBtTocart = (Button) findViewById(R.id.bt_tocart);

        mBtTocart.setOnClickListener(this);

    }

 

    @Override

    public void onClick(View v) {

        switch (v.getId()) {

            case R.id.bt_addcart:

                //添加购物车

                productDetailPresenter.addCart();

                break;

            case R.id.bt_tocart:

                //跳转到购物车

                Intent intent = new Intent(ProductDetailActivity.this, CartActivity.class);

                startActivity(intent);

                break;

        }

    }

 

    @Override

    public void getDetail(ProductDetailBean productDetailBean) {

        ProductDetailBean.DataBean dataBean = productDetailBean.getData();

        List<ProductDetailBean.DataBean> dataBeanList = new ArrayList<>();

        dataBeanList.add(dataBean);

        //设置适配器

        DetailRlvAdapter detailRlvAdapter = new DetailRlvAdapter(this, dataBeanList);

        //展示数据

        mXqRlv.setAdapter(detailRlvAdapter);

    }

 

    @Override

    public void addCart(AddCartBean addCartBean) {

        if (addCartBean.getCode().equals("0")) {

            Toast.makeText(getApplicationContext(), addCartBean.getMsg(), Toast.LENGTH_SHORT).show();

        } else {

            Toast.makeText(getApplicationContext(), addCartBean.getMsg(), Toast.LENGTH_SHORT).show();

        }

    }

 

    /**

     * 取消绑定,防止内存溢出

     */

    @Override

    protected void onDestroy() {

        super.onDestroy();

        productDetailPresenter.onDetach();

    }

}

 

```

 

> 接口

----

 

```

public interface IProductDetailView {

    //商品详情

    public void getDetail(ProductDetailBean productDetailBean);

 

    //添加购物车

    public void addCart(AddCartBean addCartBean);

}

```

 

> AddDeleteView

---------------

 

```

 

public class AddDeleteView extends LinearLayout {

    private OnAddDelClickListener listener;

    private EditText etNumber;

 

    //对外提供一个点击的回调接口

    public interface OnAddDelClickListener {

        void onAddClick(View v);

 

        void onDelClick(View v);

    }

 

    public void setOnAddDelClickListener(OnAddDelClickListener listener) {

        if (listener != null) {

            this.listener = listener;

        }

    }

 

    public AddDeleteView(Context context) {

        this(context, null);

    }

 

    public AddDeleteView(Context context, @Nullable AttributeSet attrs) {

        this(context, attrs, 0);

    }

 

    public AddDeleteView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {

        super(context, attrs, defStyleAttr);

 

        initView(context, attrs, defStyleAttr);

    }

 

    private void initView(Context context, AttributeSet attrs, int defStyleAttr) {

        View.inflate(context, R.layout.adddelete, this);

        TextView txtDelete = (TextView) findViewById(R.id.tv_delete);

        TextView txtAdd = (TextView) findViewById(R.id.tv_add);

        etNumber = (EditText) findViewById(R.id.ed_num);

 

 

        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.AddDeleteViewStyle);

 

        String leftText = typedArray.getString(R.styleable.AddDeleteViewStyle_left_text);

        String rightText = typedArray.getString(R.styleable.AddDeleteViewStyle_right_text);

        String middleText = typedArray.getString(R.styleable.AddDeleteViewStyle_middle_text);

 

        txtDelete.setText(leftText);

        txtAdd.setText(rightText);

        etNumber.setText(middleText);

 

        //回收

        typedArray.recycle();

 

 

        txtDelete.setOnClickListener(new OnClickListener() {

            @Override

            public void onClick(View view) {

                listener.onDelClick(view);

            }

        });

 

        txtAdd.setOnClickListener(new OnClickListener() {

            @Override

            public void onClick(View view) {

                listener.onAddClick(view);

            }

        });

 

    }

 

    //对外提供一个修改数字的方法

    public void setNumber(int number) {

        if (number > 0) {

            etNumber.setText(number + "");

        }

    }

 

    //对外提供一个获取当前数字的方法

    public int getNumber() {

        String string = etNumber.getText().toString();

        int i = Integer.parseInt(string);

        return i;

    }

}

 

```

 

> DingGoodsActivity

-------------------

 

```

 

public class DingGoodsActivity extends AppCompatActivity {

 

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_ding_goods);

    }

}

 

```

 

 presenter层

============

 

> CartPresenter

---------------

 

```

public class CartPresenter {

 

    private ICartView iCartView;

    private final ICartModel iCartModel;

 

    public CartPresenter(ICartView iCartView) {

        this.iCartView = iCartView;

        iCartModel = new CartModel();

    }

 

    public void getCart() {

        iCartModel.getCarts("71", new OnNetListener<CartBean>() {

            @Override

            public void onSuccess(CartBean cartBean) {

                iCartView.getCart(cartBean);

            }

 

            @Override

            public void onFailure(Throwable throwable) {

 

            }

        });

    }

 

    //解绑,防止内存溢出

    public void onDetach() {

        if (iCartView != null) {

            iCartView = null;

        }

    }

}

 

```

 

> ProductDetailPresenter

------------------------

 

```

public class ProductDetailPresenter {

    private IProductDetailView iProductDetailView;

    private final IProductDetailModel iProductDetailModel;

 

    public ProductDetailPresenter(IProductDetailView iProductDetailView) {

        this.iProductDetailView = iProductDetailView;

        iProductDetailModel = new ProductDetailModel();

    }

 

    /**

     * 商品详情

     */

    public void getProductDetail() {

        iProductDetailModel.getProductDetail("70", new OnNetListener<ProductDetailBean>() {

            @Override

            public void onSuccess(ProductDetailBean productDetailBean) {

                iProductDetailView.getDetail(productDetailBean);

            }

 

            @Override

            public void onFailure(Throwable throwable) {

 

            }

        });

    }

 

    /**

     * 添加购物车

     */

    public void addCart() {

        iProductDetailModel.addCart("70", "71", new OnNetListener<AddCartBean>() {

            @Override

            public void onSuccess(AddCartBean addCartBean) {

                iProductDetailView.addCart(addCartBean);

            }

 

            @Override

            public void onFailure(Throwable throwable) {

 

            }

        });

    }

 

    //解绑,防止内存溢出

    public void onDetach() {

        if (iProductDetailView != null) {

            iProductDetailView = null;

        }

    }

}

 

```

 

model

=====

 

> CartModel

-----------

 

```

public class CartModel implements ICartModel {

 

    @Override

    public void getCarts(String uid, final OnNetListener<CartBean> onNetListener) {

        ServiceApi serviceApi = RetrofitHelper.getServiceApi();

        serviceApi.getCarts(uid)

                .subscribeOn(Schedulers.io())

                .observeOn(AndroidSchedulers.mainThread())

                .subscribe(new Consumer<CartBean>() {

                    @Override

                    public void accept(CartBean cartBean) throws Exception {

                        onNetListener.onSuccess(cartBean);

                    }

                }, new Consumer<Throwable>() {

                    @Override

                    public void accept(Throwable throwable) throws Exception {

                        onNetListener.onFailure(throwable);

                    }

                });

    }

}

 

```

 

> 接口

----

 

```

public interface ICartModel {

    public void getCarts(String uid, OnNetListener<CartBean> onNetListener);

}

```

 

> ProductDetailModel

--------------------

 

```

public class ProductDetailModel implements IProductDetailModel {

 

    @Override

    public void getProductDetail(String pid, final OnNetListener<ProductDetailBean> onNetListener) {

        ServiceApi serviceApi = RetrofitHelper.getServiceApi();

        serviceApi.getDetail(pid)

                .subscribeOn(Schedulers.io())

                .observeOn(AndroidSchedulers.mainThread())

                .subscribe(new Consumer<ProductDetailBean>() {

                    @Override

                    public void accept(ProductDetailBean productDetailBean) throws Exception {

                        onNetListener.onSuccess(productDetailBean);

                    }

                }, new Consumer<Throwable>() {

                    @Override

                    public void accept(Throwable throwable) throws Exception {

                        onNetListener.onFailure(throwable);

                    }

                });

    }

 

    @Override

    public void addCart(String pid, String uid, final OnNetListener<AddCartBean> onNetListener) {

        ServiceApi serviceApi = RetrofitHelper.getServiceApi();

        serviceApi.addCart(pid, uid)

                .subscribeOn(Schedulers.io())

                .observeOn(AndroidSchedulers.mainThread())

                .subscribe(new Consumer<AddCartBean>() {

                    @Override

                    public void accept(AddCartBean addCartBean) throws Exception {

                        onNetListener.onSuccess(addCartBean);

                    }

                }, new Consumer<Throwable>() {

                    @Override

                    public void accept(Throwable throwable) throws Exception {

                        onNetListener.onFailure(throwable);

                    }

                });

 

    }

}

 

```

 

> 接口

----

 

```

public interface IProductDetailModel {

    public void getProductDetail(String pid, OnNetListener<ProductDetailBean> onNetListener);

 

    public void addCart(String pid, String uid, OnNetListener<AddCartBean> onNetListener);

}

 

```

 

Adapter

=======

 

> DetailRlvAdapter

------------------

 

```

 

public class DetailRlvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context context;

    private List<ProductDetailBean.DataBean> dataList;

    private LayoutInflater inflater;

 

    public DetailRlvAdapter(Context context, List<ProductDetailBean.DataBean> dataList) {

        this.context = context;

        this.dataList = dataList;

        inflater = LayoutInflater.from(context);

    }

 

    @Override

    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = inflater.inflate(R.layout.detail_rlv_adapter_item, null);

        return new MyViewHplder(view);

    }

 

    @Override

    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

        MyViewHplder myViewHplder = (MyViewHplder) holder;

 

        ProductDetailBean.DataBean dataBean = dataList.get(position);

 

        String[] images = dataBean.getImages().split("\\!");

        myViewHplder.mDetailAdapterSdv.setImageURI(images[0]);

        myViewHplder.mTvDetailTitle.setText(dataBean.getTitle());

        myViewHplder.mTvDetailPrice.setText("¥" + dataBean.getPrice());

        myViewHplder.mTvDetailSj.setText("我是商家" + dataBean.getSellerid());

    }

 

    @Override

    public int getItemCount() {

        if (dataList == null) {

            return 0;

        }

        return dataList.size();

    }

 

    class MyViewHplder extends RecyclerView.ViewHolder {

        SimpleDraweeView mDetailAdapterSdv;

        TextView mTvDetailTitle;

        TextView mTvDetailPrice;

        TextView mTvDetailSj;

 

        public MyViewHplder(View itemView) {

            super(itemView);

            mDetailAdapterSdv = (SimpleDraweeView) itemView.findViewById(R.id.detail_adapter_sdv);

            mTvDetailTitle = (TextView) itemView.findViewById(R.id.tv_detail_title);

            mTvDetailPrice = (TextView) itemView.findViewById(R.id.tv_detail_price);

            mTvDetailSj = (TextView) itemView.findViewById(R.id.tv_detail_sj);

        }

    }

 

}

 

```

 

> MyElvAdapter

--------------

 

```

public class MyElvAdapter extends BaseExpandableListAdapter {

    private Context context;

        private List<CartBean.DataBean> groupList;

        private List<List<CartBean.DataBean.ListBean>> childList;

        private LayoutInflater inflater;

 

        public MyElvAdapter(Context context, List<CartBean.DataBean> groupList, List<List<CartBean.DataBean.ListBean>> childList) {

            this.context = context;

            this.groupList = groupList;

            this.childList = childList;

            inflater = LayoutInflater.from(context);

        }

 

        @Override

        public int getGroupCount() {

            return groupList.size();

        }

 

        @Override

        public int getChildrenCount(int groupPosition) {

            return childList.get(groupPosition).size();

        }

 

        @Override

        public Object getGroup(int groupPosition) {

            return groupList.get(groupPosition);

        }

 

        @Override

        public Object getChild(int groupPosition, int childPosition) {

            return childList.get(groupPosition).get(childPosition);

        }

 

        @Override

        public long getGroupId(int groupPosition) {

            return groupPosition;

        }

 

        @Override

        public long getChildId(int groupPosition, int childPosition) {

            return childPosition;

        }

 

        @Override

        public boolean hasStableIds() {

            return false;

        }

 

        @Override

        public View getGroupView(final int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {

            View view;

            final GroupViewHolder holder;

            if (convertView == null) {

                holder = new GroupViewHolder();

                view = inflater.inflate(R.layout.cart_group_item, null);

                holder.cb_group = view.findViewById(R.id.cb_group);

                holder.tv_dian = view.findViewById(R.id.gou_dian);

                view.setTag(holder);

            } else {

                view = convertView;

                holder = (GroupViewHolder) view.getTag();

            }

            final CartBean.DataBean dataBean = groupList.get(groupPosition);

            holder.cb_group.setChecked(dataBean.isChecked());

            holder.tv_dian.setText(dataBean.getSellerName());

            //一级列表的Checkbox

            holder.cb_group.setOnClickListener(new View.OnClickListener() {

                @Override

                public void onClick(View v) {

                    dataBean.setChecked(holder.cb_group.isChecked());

                    //当一级选中时,改变二级列表CheckBox状态

                    changeChildCbState(groupPosition, holder.cb_group.isChecked());

                    //将对应的数量和价格传到PriceAndCountEvent

                    EventBus.getDefault().post(computer());

                    //当一级的全部选中是,改变全选CheckBox状态

                    changeAllCbState(isAllGroupCbSelected());

                    //刷新列表

                    notifyDataSetChanged();

                }

            });

            return view;

        }

 

        @Override

        public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {

            View view;

            final ChildViewHolder holder;

            if (convertView == null) {

                holder = new ChildViewHolder();

                view = inflater.inflate(R.layout.cart_child_item, null);

                holder.cb_child = view.findViewById(R.id.cb_child);

                holder.del = view.findViewById(R.id.del);

                holder.sdv = view.findViewById(R.id.child_sdv);

                holder.adv_main = view.findViewById(R.id.adv_main);

                holder.tv_info = view.findViewById(R.id.child_info);

                holder.tv_price = view.findViewById(R.id.child_price);

                holder.tv_tit = view.findViewById(R.id.child_tit);

                view.setTag(holder);

            } else {

                view = convertView;

                holder = (ChildViewHolder) view.getTag();

            }

            final CartBean.DataBean.ListBean listBean = childList.get(groupPosition).get(childPosition);

            holder.cb_child.setChecked(listBean.isChecked());

            String[] strings = listBean.getImages().split("\\!");

            holder.sdv.setImageURI(strings[0]);

            holder.tv_tit.setText(listBean.getSubhead());

            holder.tv_info.setText("日期:"+listBean.getCreatetime());

            holder.tv_price.setText("¥" + listBean.getBargainPrice());

            //给二级CheckBox设置点击事件

            holder.cb_child.setOnClickListener(new View.OnClickListener() {

                @Override

                public void onClick(View v) {

                    //设置该条目对象里的checked属性值

                    listBean.setChecked(holder.cb_child.isChecked());

                    PriceAndCountEvent priceAndCountEvent = computer();

                    EventBus.getDefault().post(priceAndCountEvent);

 

                    if (holder.cb_child.isChecked()) {

                        //当前checkbox是选中状态

                        if (isAllChildCbSelected(groupPosition)) {

                            changeGroupCbState(groupPosition, true);

                            changeAllCbState(isAllGroupCbSelected());

                        }

                    } else {

                        changeGroupCbState(groupPosition, false);

                        changeAllCbState(isAllGroupCbSelected());

                    }

                    notifyDataSetChanged();

                }

            });

            //自定义View加减号

            holder.adv_main.setOnAddDelClickListener(new AddDeleteView.OnAddDelClickListener() {

                @Override

                public void onAddClick(View v) {

                    //加号

                    int num = listBean.getNum();

                    holder.adv_main.setNumber(++num);

                    listBean.setNum(num);

                    if (holder.cb_child.isChecked()) {

                        PriceAndCountEvent priceAndCountEvent = computer();

                        EventBus.getDefault().post(computer());

                    }

                }

 

                @Override

                public void onDelClick(View v) {

                    //减号

                    int num = listBean.getNum();

                    if (num == 1) {

                        return;

                    }

                    holder.adv_main.setNumber(--num);

                    listBean.setNum(num);

                    if (holder.cb_child.isChecked()) {

                        PriceAndCountEvent priceAndCountEvent = computer();

                        EventBus.getDefault().post(computer());

                    }

                }

            });

 

            holder.del.setOnLongClickListener(new View.OnLongClickListener() {

                @Override

                public boolean onLongClick(View view) {

                    AlertDialog.Builder builder = new AlertDialog.Builder(context);

                    builder.setIcon(R.mipmap.ic_launcher_round)

                            .setTitle("删除商品")

                            .setMessage("确定删除商品吗?");

                    builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {

                        @Override

                        public void onClick(DialogInterface dialog, int which) {

                            List<CartBean.DataBean.ListBean> datasBeen = childList.get(groupPosition);

                            CartBean.DataBean.ListBean remove = datasBeen.remove(childPosition);

                            if (datasBeen.size() == 0) {

                                childList.remove(groupPosition);

                                groupList.remove(groupPosition);

                            }

                            EventBus.getDefault().post(computer());

                            notifyDataSetChanged();

                        }

                    });

                    builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {

                        @Override

                        public void onClick(DialogInterface dialog, int which) {

                            Toast.makeText(context, "您取消了删除" + which, Toast.LENGTH_SHORT).show();

                        }

                    });

                    builder.show();

                    return true;

                }

            });

            return view;

        }

 

        @Override

        public boolean isChildSelectable(int groupPosition, int childPosition) {

            return true;

        }

 

        class GroupViewHolder {

            CheckBox cb_group;

            TextView tv_dian;

        }

 

        class ChildViewHolder {

            LinearLayout del;

            CheckBox cb_child;

            SimpleDraweeView sdv;

            TextView tv_tit;

            TextView tv_info;

            TextView tv_price;

            AddDeleteView adv_main;

        }

 

        /**

         * 改变全选CheckBox状态

         *

         * @param flag

         */

        private void changeAllCbState(boolean flag) {

            MessageEvent messageEvent = new MessageEvent();

            messageEvent.setChecked(flag);

            EventBus.getDefault().post(messageEvent);

        }

 

        /**

         * 改变二级列表CheckBox状态

         *

         * @param groupPosition

         * @param flag

         */

        private void changeChildCbState(int groupPosition, boolean flag) {

            List<CartBean.DataBean.ListBean> listBeans = childList.get(groupPosition);

            for (int i = 0; i < listBeans.size(); i++) {

                CartBean.DataBean.ListBean listBean = listBeans.get(i);

                listBean.setChecked(flag);

            }

        }

 

        /**

         * 改变一级列表CheckBox状态

         *

         * @param groupPosition

         * @param flag

         */

        private void changeGroupCbState(int groupPosition, boolean flag) {

            CartBean.DataBean dataBean = groupList.get(groupPosition);

            dataBean.setChecked(flag);

        }

 

        /**

         * 判断一级列表是否全部选中

         *

         * @return

         */

        public boolean isAllGroupCbSelected() {

            for (int i = 0; i < groupList.size(); i++) {

                CartBean.DataBean dataBean = groupList.get(i);

                if (!dataBean.isChecked()) {

                    return false;

                }

            }

            return true;

        }

 

        /**

         * 判断二级列表是否全部选中

         *

         * @param groupPosition

         * @return

         */

        public boolean isAllChildCbSelected(int groupPosition) {

            List<CartBean.DataBean.ListBean> listBeans = childList.get(groupPosition);

            for (int i = 0; i < listBeans.size(); i++) {

                CartBean.DataBean.ListBean listBean = listBeans.get(i);

                if (!listBean.isChecked()) {

                    return false;

                }

            }

            return true;

        }

 

        /**

         * 设置全选、反选

         *

         * @param flag

         */

        public void changeAllListCbState(boolean flag) {

            for (int i = 0; i < groupList.size(); i++) {

                //改变一级列表CheckBox状态

                changeGroupCbState(i, flag);

                //改变二级列表CheckBox状态

                changeChildCbState(i, flag);

            }

            //将数量和价格传值

            EventBus.getDefault().post(computer());

            //刷新列表

            notifyDataSetChanged();

        }

 

        /**

         * 计算列表中选中的钱和数量

         *

         * @return

         */

        private PriceAndCountEvent computer() {

            int count = 0;

            int price = 0;

            for (int i = 0; i < childList.size(); i++) {

                List<CartBean.DataBean.ListBean> listBeans = childList.get(i);

                for (int j = 0; j < listBeans.size(); j++) {

                    CartBean.DataBean.ListBean listBean = listBeans.get(j);

                    if (listBean.isChecked()) {

                        count += listBean.getNum();

                        price += listBean.getNum() * listBean.getPrice();

                    }

                }

            }

            PriceAndCountEvent priceAndCountEvent = new PriceAndCountEvent();

            priceAndCountEvent.setCount(count);

            priceAndCountEvent.setPrice(price);

            return priceAndCountEvent;

        }

}

 

```

 

eventbus

========

 

> MessageEvent

--------------

 

```

public class MessageEvent {

    public boolean checked;

 

    public boolean isChecked() {

        return checked;

    }

 

    public void setChecked(boolean checked) {

        this.checked = checked;

    }

}

 

```

 

> PriceAndCountEvent

--------------------

 

```

public class PriceAndCountEvent {

    private int price;

    private int count;

 

    public int getPrice() {

        return price;

    }

 

    public void setPrice(int price) {

        this.price = price;

    }

 

    public int getCount() {

        return count;

    }

 

    public void setCount(int count) {

        this.count = count;

    }

}

 

```

 

Bean

====

 

> AddCartBean

-------------

 

```

package com.bwie.moni_demo.bean;

 

/**

 * Created by liyongkai on 2018-03-05.

 */

 

public class AddCartBean {

    /**

     * msg : 加购成功

     * code : 0

     */

 

    private String msg;

    private String code;

 

    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;

    }

}

 

```

 

> CartBean

----------

 

```

package com.bwie.moni_demo.bean;

 

import java.util.List;

 

/**

 * Created by liyongkai on 2018-03-05.

 */

 

public class CartBean {

 

 

    /**

     * msg : 请求成功

     * code : 0

     * data : [{"list":[{"bargainPrice":11800,"createtime":"2017-10-14T21:38:26","detailUrl":"https://item.m.jd.com/product/5025518.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t8830/106/1760940277/195595/5cf9412f/59bf2ef5N5ab7dc16.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5428/70/1520969931/274676/b644dd0d/591128e7Nd2f70da0.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5566/365/1519564203/36911/620c750c/591128eaN54ac3363.jpg!q70.jpg","num":3,"pid":58,"price":6399,"pscid":40,"selected":0,"sellerid":2,"subhead":"升级4G大显存!Nvme协议Pcie SSD,速度快人一步】GTX1050Ti就选拯救者!专业游戏键盘&新模具全新设计!","title":"联想(Lenovo)拯救者R720 15.6英寸游戏笔记本电脑(i5-7300HQ 8G 1T+128G SSD GTX1050Ti 4G IPS 黑)"}],"sellerName":"商家2","sellerid":"2"},{"list":[{"bargainPrice":11800,"createtime":"2017-10-14T21:48:08","detailUrl":"https://mitem.jd.hk/ware/view.action?wareId=1988853309&cachekey=1acb07a701ece8d2434a6ae7fa6870a1","images":"https://m.360buyimg.com/n0/jfs/t6130/97/1370670410/180682/1109582a/593276b1Nd81fe723.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5815/178/2614671118/51656/7f52d137/593276c7N107b725a.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5878/60/2557817477/30873/4502b606/593276caN5a7d6357.jpg!q70.jpg","num":3,"pid":60,"price":13888,"pscid":40,"selected":0,"sellerid":4,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"}],"sellerName":"商家4","sellerid":"4"},{"list":[{"bargainPrice":111.99,"createtime":"2017-10-03T23:43:53","detailUrl":"https://item.m.jd.com/product/4719303.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t9004/210/1160833155/647627/ad6be059/59b4f4e1N9a2b1532.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7504/338/63721388/491286/f5957f53/598e95f1N7f2adb87.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7441/10/64242474/419246/adb30a7d/598e95fbNd989ba0a.jpg!q70.jpg","num":1,"pid":12,"price":256,"pscid":1,"selected":0,"sellerid":5,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellerName":"商家5","sellerid":"5"},{"list":[{"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","num":8,"pid":17,"price":299,"pscid":1,"selected":0,"sellerid":10,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellerName":"商家10","sellerid":"10"},{"list":[{"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","num":3,"pid":18,"price":399,"pscid":1,"selected":0,"sellerid":11,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellerName":"商家11","sellerid":"11"},{"list":[{"bargainPrice":111.99,"createtime":"2017-10-14T21:39:05","detailUrl":"https://item.m.jd.com/product/4719303.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t9004/210/1160833155/647627/ad6be059/59b4f4e1N9a2b1532.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7504/338/63721388/491286/f5957f53/598e95f1N7f2adb87.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7441/10/64242474/419246/adb30a7d/598e95fbNd989ba0a.jpg!q70.jpg","num":3,"pid":19,"price":499,"pscid":1,"selected":0,"sellerid":12,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellerName":"商家12","sellerid":"12"},{"list":[{"bargainPrice":11800,"createtime":"2017-10-14T21:38:26","detailUrl":"https://mitem.jd.hk/ware/view.action?wareId=1988853309&cachekey=1acb07a701ece8d2434a6ae7fa6870a1","images":"https://m.360buyimg.com/n0/jfs/t6130/97/1370670410/180682/1109582a/593276b1Nd81fe723.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5815/178/2614671118/51656/7f52d137/593276c7N107b725a.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5878/60/2557817477/30873/4502b606/593276caN5a7d6357.jpg!q70.jpg","num":1,"pid":70,"price":17999,"pscid":40,"selected":0,"sellerid":14,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"}],"sellerName":"商家14","sellerid":"14"},{"list":[{"bargainPrice":11800,"createtime":"2017-10-03T23:53:28","detailUrl":"https://mitem.jd.hk/ware/view.action?wareId=1988853309&cachekey=1acb07a701ece8d2434a6ae7fa6870a1","images":"https://m.360buyimg.com/n0/jfs/t6130/97/1370670410/180682/1109582a/593276b1Nd81fe723.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5815/178/2614671118/51656/7f52d137/593276c7N107b725a.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5878/60/2557817477/30873/4502b606/593276caN5a7d6357.jpg!q70.jpg","num":8,"pid":71,"price":32999,"pscid":40,"selected":0,"sellerid":15,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"}],"sellerName":"商家15","sellerid":"15"},{"list":[{"bargainPrice":111.99,"createtime":"2017-10-14T21:39:05","detailUrl":"https://item.m.jd.com/product/4719303.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t9004/210/1160833155/647627/ad6be059/59b4f4e1N9a2b1532.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7504/338/63721388/491286/f5957f53/598e95f1N7f2adb87.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7441/10/64242474/419246/adb30a7d/598e95fbNd989ba0a.jpg!q70.jpg","num":9,"pid":1,"price":118,"pscid":1,"selected":0,"sellerid":17,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellerName":"商家17","sellerid":"17"}]

     */

 

    private String msg;

    private String code;

    private List<DataBean> data;

 

    public String getMsg() {

        return msg;

    }

 

    public void setMsg(String msg) {

        this.msg = msg;

    }

 

    public String getCode() {

        return code;

    }

 

    public void setCode(String code) {

        this.code = code;

    }

 

    public List<DataBean> getData() {

        return data;

    }

 

    public void setData(List<DataBean> data) {

        this.data = data;

    }

 

    public static class DataBean {

        /**

         * list : [{"bargainPrice":11800,"createtime":"2017-10-14T21:38:26","detailUrl":"https://item.m.jd.com/product/5025518.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t8830/106/1760940277/195595/5cf9412f/59bf2ef5N5ab7dc16.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5428/70/1520969931/274676/b644dd0d/591128e7Nd2f70da0.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5566/365/1519564203/36911/620c750c/591128eaN54ac3363.jpg!q70.jpg","num":3,"pid":58,"price":6399,"pscid":40,"selected":0,"sellerid":2,"subhead":"升级4G大显存!Nvme协议Pcie SSD,速度快人一步】GTX1050Ti就选拯救者!专业游戏键盘&新模具全新设计!","title":"联想(Lenovo)拯救者R720 15.6英寸游戏笔记本电脑(i5-7300HQ 8G 1T+128G SSD GTX1050Ti 4G IPS 黑)"}]

         * sellerName : 商家2

         * sellerid : 2

         */

        private boolean checked = true;

        private String sellerName;

        private String sellerid;

        private List<ListBean> list;

 

        public boolean isChecked() {

            return checked;

        }

 

        public void setChecked(boolean checked) {

            this.checked = checked;

        }

 

        public String getSellerName() {

            return sellerName;

        }

 

        public void setSellerName(String sellerName) {

            this.sellerName = sellerName;

        }

 

        public String getSellerid() {

            return sellerid;

        }

 

        public void setSellerid(String sellerid) {

            this.sellerid = sellerid;

        }

 

        public List<ListBean> getList() {

            return list;

        }

 

        public void setList(List<ListBean> list) {

            this.list = list;

        }

 

        public static class ListBean {

            /**

             * bargainPrice : 11800

             * createtime : 2017-10-14T21:38:26

             * detailUrl : https://item.m.jd.com/product/5025518.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends

             * images : https://m.360buyimg.com/n0/jfs/t8830/106/1760940277/195595/5cf9412f/59bf2ef5N5ab7dc16.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5428/70/1520969931/274676/b644dd0d/591128e7Nd2f70da0.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5566/365/1519564203/36911/620c750c/591128eaN54ac3363.jpg!q70.jpg

             * num : 3

             * pid : 58

             * price : 6399

             * pscid : 40

             * selected : 0

             * sellerid : 2

             * subhead : 升级4G大显存!Nvme协议Pcie SSD,速度快人一步】GTX1050Ti就选拯救者!专业游戏键盘&新模具全新设计!

             * title : 联想(Lenovo)拯救者R720 15.6英寸游戏笔记本电脑(i5-7300HQ 8G 1T+128G SSD GTX1050Ti 4G IPS 黑)

             */

            private boolean checked = true;

            private double bargainPrice;

            private String createtime;

            private String detailUrl;

            private String images;

            private int num;

            private int pid;

            private double price;

            private int pscid;

            private int selected;

            private int sellerid;

            private String subhead;

            private String title;

 

            public boolean isChecked() {

                return checked;

            }

 

            public void setChecked(boolean checked) {

                this.checked = checked;

            }

 

            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;

            }

        }

    }

}

 

```

 

> DingDBean

-----------

 

```

package com.bwie.moni_demo.bean;

 

import java.util.List;

 

/**

 * Created by liyongkai on 2018/3/5.

 */

 

public class DingDBean {

    /**

     * msg : 请求成功

     * code : 0

     * data : [{"createtime":"2017-11-09T09:17:20","orderid":1446,"price":99.99,"status":1,"title":"订单标题测试","uid":71},{"createtime":"2017-11-09T09:20:58","orderid":1448,"price":256.99,"status":1,"title":"订单标题测试","uid":71},{"createtime":"2017-11-09T09:22:41","orderid":1458,"price":999,"status":1,"title":"订单测试标题","uid":71},{"createtime":"2017-11-09T09:22:41","orderid":1464,"price":156,"status":1,"title":"订单测试标题","uid":71},{"createtime":"2017-12-18T14:55:20","orderid":3459,"price":99.99,"status":1,"title":"订单测试标题71","uid":71},{"createtime":"2017-12-19T20:13:37","orderid":3564,"price":99.99,"status":1,"title":"订单测试标题71","uid":71},{"createtime":"2017-12-20T11:01:10","orderid":3639,"price":1001,"status":1,"title":"订单测试标题71","uid":71},{"createtime":"2017-12-20T11:02:57","orderid":3640,"price":99.99,"status":1,"title":"订单测试标题71","uid":71},{"createtime":"2017-12-20T11:15:37","orderid":3645,"price":99.99,"status":1,"title":"订单测试标题71","uid":71},{"createtime":"2017-12-20T11:58:36","orderid":3723,"price":99.99,"status":1,"title":"订单测试标题71","uid":71}]

     * page : 1

     */

 

    private String msg;

    private String code;

    private String page;

    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 String getPage() {

        return page;

    }

 

    public void setPage(String page) {

        this.page = page;

    }

 

    public List<DataBean> getData() {

        return data;

    }

 

    public void setData(List<DataBean> data) {

        this.data = data;

    }

 

    public static class DataBean {

        /**

         * createtime : 2017-11-09T09:17:20

         * orderid : 1446

         * price : 99.99

         * status : 1

         * title : 订单标题测试

         * uid : 71

         */

 

        private String createtime;

        private int orderid;

        private double price;

        private int status;

        private String title;

        private int uid;

 

        public String getCreatetime() {

            return createtime;

        }

 

        public void setCreatetime(String createtime) {

            this.createtime = createtime;

        }

 

        public int getOrderid() {

            return orderid;

        }

 

        public void setOrderid(int orderid) {

            this.orderid = orderid;

        }

 

        public double getPrice() {

            return price;

        }

 

        public void setPrice(double price) {

            this.price = price;

        }

 

        public int getStatus() {

            return status;

        }

 

        public void setStatus(int status) {

            this.status = status;

        }

 

        public String getTitle() {

            return title;

        }

 

        public void setTitle(String title) {

            this.title = title;

        }

 

        public int getUid() {

            return uid;

        }

 

        public void setUid(int uid) {

            this.uid = uid;

        }

    }

}

 

```

 

> ProductDetailBean

-------------------

 

```

package com.bwie.moni_demo.bean;

 

/**

 * Created by liyongkai on 2018-03-05.

 */

 

public class ProductDetailBean {

 

    /**

     * msg :

     * seller : {"description":"我是商家14","icon":"http://120.27.23.105/images/icon.png","name":"商家14","productNums":999,"score":5,"sellerid":14}

     * code : 0

     * data : {"bargainPrice":11800,"createtime":"2017-10-14T21:38:26","detailUrl":"https://mitem.jd.hk/ware/view.action?wareId=1988853309&cachekey=1acb07a701ece8d2434a6ae7fa6870a1","images":"https://m.360buyimg.com/n0/jfs/t6130/97/1370670410/180682/1109582a/593276b1Nd81fe723.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5815/178/2614671118/51656/7f52d137/593276c7N107b725a.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5878/60/2557817477/30873/4502b606/593276caN5a7d6357.jpg!q70.jpg","itemtype":1,"pid":70,"price":17999,"pscid":40,"salenum":545,"sellerid":14,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"}

     */

 

    private String msg;

    private SellerBean seller;

    private String code;

    private DataBean data;

 

    public String getMsg() {

        return msg;

    }

 

    public void setMsg(String msg) {

        this.msg = msg;

    }

 

    public SellerBean getSeller() {

        return seller;

    }

 

    public void setSeller(SellerBean seller) {

        this.seller = seller;

    }

 

    public String getCode() {

        return code;

    }

 

    public void setCode(String code) {

        this.code = code;

    }

 

    public DataBean getData() {

        return data;

    }

 

    public void setData(DataBean data) {

        this.data = data;

    }

 

    public static class SellerBean {

        /**

         * description : 我是商家14

         * icon : http://120.27.23.105/images/icon.png

         * name : 商家14

         * productNums : 999

         * score : 5

         * sellerid : 14

         */

 

        private String description;

        private String icon;

        private String name;

        private int productNums;

        private int score;

        private int sellerid;

 

        public String getDescription() {

            return description;

        }

 

        public void setDescription(String description) {

            this.description = description;

        }

 

        public String getIcon() {

            return icon;

        }

 

        public void setIcon(String icon) {

            this.icon = icon;

        }

 

        public String getName() {

            return name;

        }

 

        public void setName(String name) {

            this.name = name;

        }

 

        public int getProductNums() {

            return productNums;

        }

 

        public void setProductNums(int productNums) {

            this.productNums = productNums;

        }

 

        public int getScore() {

            return score;

        }

 

        public void setScore(int score) {

            this.score = score;

        }

 

        public int getSellerid() {

            return sellerid;

        }

 

        public void setSellerid(int sellerid) {

            this.sellerid = sellerid;

        }

    }

 

    public static class DataBean {

        /**

         * bargainPrice : 11800

         * createtime : 2017-10-14T21:38:26

         * detailUrl : https://mitem.jd.hk/ware/view.action?wareId=1988853309&cachekey=1acb07a701ece8d2434a6ae7fa6870a1

         * images : https://m.360buyimg.com/n0/jfs/t6130/97/1370670410/180682/1109582a/593276b1Nd81fe723.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5815/178/2614671118/51656/7f52d137/593276c7N107b725a.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5878/60/2557817477/30873/4502b606/593276caN5a7d6357.jpg!q70.jpg

         * itemtype : 1

         * pid : 70

         * price : 17999

         * pscid : 40

         * salenum : 545

         * sellerid : 14

         * subhead : 购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)

         * title : 全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G

         */

 

        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;

 

        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;

        }

    }

}

 

```

 

布局

==

 

> activity_cart.xml

-------------------

 

```

<?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.bwie.moni_demo.CartActivity">

    <RelativeLayout

        android:layout_width="match_parent"

        android:layout_height="wrap_content">

 

        <TextView

            android:layout_width="30dp"

            android:layout_height="30dp"

            android:layout_centerVertical="true"

            android:background="@drawable/leftjiantou" />

 

        <TextView

            android:layout_width="match_parent"

            android:layout_height="40dp"

            android:gravity="center"

            android:text="购物车"

            android:textColor="#000"

            android:textSize="25sp" />

 

        <TextView

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_alignParentRight="true"

            android:layout_centerVertical="true"

            android:layout_marginRight="20dp"

            android:text="编辑" />

    </RelativeLayout>

 

 

    <ExpandableListView

        android:id="@+id/elv"

        android:layout_width="match_parent"

        android:layout_height="match_parent"

        android:layout_weight="1" />

 

    <RelativeLayout

        android:layout_width="match_parent"

        android:layout_height="70dp"

        android:layout_alignParentBottom="true"

        android:background="@android:color/white"

        android:gravity="center_vertical">

 

        <CheckBox

            android:id="@+id/cb_All"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_centerVertical="true"

            android:layout_marginLeft="10dp"

            android:checked="true"

            android:focusable="false" />

 

        <TextView

            android:id="@+id/tv_quxuan"

            android:layout_width="wrap_content"

            android:layout_height="50dp"

            android:layout_centerVertical="true"

            android:layout_marginLeft="10dp"

            android:layout_toRightOf="@+id/cb_All"

            android:gravity="center_vertical"

            android:text="全选"

            android:textSize="20sp" />

 

 

        <LinearLayout

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_toRightOf="@id/tv_quxuan"

            android:orientation="vertical">

 

            <TextView

                android:id="@+id/tv_price"

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:layout_marginLeft="10dp"

                android:text="合计:¥550.90"

                android:textSize="25dp" />

 

            <TextView

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:layout_marginLeft="100dp"

                android:text="不含运费" />

 

        </LinearLayout>

 

        <TextView

            android:id="@+id/tv_num"

            android:layout_width="120dp"

            android:layout_height="match_parent"

            android:layout_alignParentRight="true"

            android:background="#FC7903"

            android:gravity="center"

            android:padding="10dp"

            android:text="去支付(0)"

            android:textColor="@android:color/white" />

    </RelativeLayout>

</LinearLayout>

 

```

 

> activity_ding_goods.xml

-------------------------

 

```

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout 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"

    tools:context="com.bwie.moni_demo.DingGoodsActivity">

    <!--<RelativeLayout-->

        <!--android:layout_width="match_parent"-->

        <!--android:layout_height="60dp"-->

        <!-->-->

        <!--<TextView-->

            <!--android:layout_centerInParent="true"-->

            <!--android:layout_width="wrap_content"-->

            <!--android:layout_height="wrap_content"-->

            <!--android:textSize="20sp"-->

            <!--android:text="订单页面"-->

            <!--/>-->

        <!--<ImageView-->

            <!--android:src="@mipmap/ic_launcher"-->

            <!--android:layout_width="25dp"-->

            <!--android:layout_height="25dp"-->

            <!--android:id="@+id/imageView"-->

            <!--android:layout_alignParentRight="true"-->

            <!--android:layout_centerVertical="true"-->

            <!--/>-->

    <!--</RelativeLayout>-->

    <!--<TextView-->

        <!--android:layout_width="match_parent"-->

        <!--android:layout_height="1dp"-->

        <!--android:background="#000"-->

        <!--/>-->

    <!--<android.support.design.widget.TabLayout-->

        <!--android:id="@+id/tabLayout"-->

        <!--android:layout_width="match_parent"-->

        <!--android:layout_height="50dp"-->

        <!-->-->

    <!--</android.support.design.widget.TabLayout>-->

 

    <!--<android.support.v4.view.ViewPager-->

        <!--android:id="@+id/viewPager"-->

        <!--android:layout_width="match_parent"-->

        <!--android:layout_height="match_parent"-->

        <!-->-->

    <!--</android.support.v4.view.ViewPager>-->

</RelativeLayout>

 

```

 

> activity_main.xml

-------------------

 

```

<?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.bwie.moni_demo.MainActivity">

 

    <LinearLayout

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:orientation="horizontal">

 

 

        <Button

            android:id="@+id/bt_xiazai"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:text="下载" />

 

        <Button

            android:id="@+id/bt_zanting"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:text="暂停" />

 

        <Button

            android:id="@+id/bt_jixu"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:text="继续" />

    </LinearLayout>

 

    <ProgressBar

        android:id="@+id/pro"

        style="?android:attr/progressBarStyleHorizontal"

        android:layout_width="match_parent"

        android:layout_height="20dp" />

 

    <TextView

        android:id="@+id/tv_progress"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_gravity="center"

        android:text="下载:0%" />

 

    <Button

        android:id="@+id/bt_xiangqing"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:layout_marginTop="50dp"

        android:layout_marginLeft="50dp"

        android:layout_marginRight="50dp"

        android:text="进入详情" />

 

</LinearLayout>

 

```

 

> activity_product_detail.xml

-----------------------------

 

```

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout 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"

    tools:context="com.bwie.moni_demo.ProductDetailActivity">

 

    <LinearLayout

        android:id="@+id/lin_top"

        android:layout_width="match_parent"

        android:layout_height="wrap_content">

 

        <include

            layout="@layout/simple_player_view_player"

            android:layout_width="match_parent"

            android:layout_height="250dp" />

    </LinearLayout>

 

 

    <android.support.v7.widget.RecyclerView

        android:id="@+id/xq_rlv"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:layout_below="@id/lin_top" />

 

    <LinearLayout

        android:layout_width="match_parent"

        android:layout_height="80dp"

        android:layout_alignParentBottom="true"

        android:orientation="horizontal">

 

        <ImageView

            android:layout_width="65dp"

            android:layout_height="match_parent"

            android:background="@drawable/kefu" />

 

        <ImageView

            android:layout_width="65dp"

            android:layout_height="match_parent"

            android:background="@drawable/dianjia" />

 

        <ImageView

            android:id="@+id/iv_getcart"

            android:layout_width="65dp"

            android:layout_height="match_parent"

            android:background="@drawable/shoucnag" />

 

        <Button

            android:id="@+id/bt_addcart"

            android:layout_width="150dp"

            android:layout_height="match_parent"

            android:background="#FDC302"

            android:text="添加到购物车"

            android:textColor="#fff"

            android:textSize="16sp" />

 

        <Button

            android:id="@+id/bt_tocart"

            android:layout_width="120dp"

            android:layout_height="match_parent"

            android:background="#FF6A04"

            android:text="立即购买"

            android:textColor="#fff"

            android:textSize="16sp" />

    </LinearLayout>

</RelativeLayout>

 

```

 

>adddelete.xml

--------------

 

```

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="match_parent"

    android:layout_height="match_parent">

 

    <TextView

        android:id="@+id/tv_delete"

        android:layout_width="31dp"

        android:layout_height="31dp"

        android:background="#999999"

        android:gravity="center"

        android:text="-"

        android:textSize="20sp" />

 

    <EditText

        android:id="@+id/ed_num"

        android:layout_width="30dp"

        android:layout_height="30dp"

        android:background="@null"

        android:gravity="center" />

 

    <TextView

        android:id="@+id/tv_add"

        android:layout_width="31dp"

        android:layout_height="31dp"

        android:background="#999999"

        android:gravity="center"

        android:text="+"

        android:textSize="20sp" />

</LinearLayout>

```

 

> cart_child_item.xml

---------------------

 

```

<?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"

    android:id="@+id/del"

    android:layout_width="match_parent"

    android:layout_height="120dp"

    android:orientation="horizontal">

 

    <CheckBox

        android:id="@+id/cb_child"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_marginBottom="30dp"

        android:layout_marginLeft="20dp"

        android:layout_marginTop="45dp"

        android:focusable="false" />

 

 

    <com.facebook.drawee.view.SimpleDraweeView

        android:id="@+id/child_sdv"

        android:layout_width="100dp"

        android:layout_height="match_parent"

        android:layout_margin="8dp"

        app:placeholderImage="@mipmap/ic_launcher_round" />

 

    <LinearLayout

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:layout_marginLeft="20dp"

        android:orientation="vertical"

        android:padding="10dp">

 

        <TextView

            android:id="@+id/child_tit"

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:text="123"

            android:textStyle="bold" />

 

        <TextView

            android:id="@+id/child_info"

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:layout_marginTop="8dp"

            android:text="颜色:黑;尺寸:23L" />

 

        <RelativeLayout

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:layout_marginTop="30dp"

            android:orientation="horizontal">

 

            <TextView

                android:id="@+id/child_price"

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:textSize="20sp"

                android:text="¥"

                android:textColor="#E17E52" />

 

            <com.bwie.moni_demo.view.AddDeleteView

                android:id="@+id/adv_main"

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:layout_alignParentRight="true"

                android:layout_weight="1"

                app:left_text="-"

                app:middle_text="1"

                app:right_text="+" />

        </RelativeLayout>

 

    </LinearLayout>

</LinearLayout>

```

 

> cart_group_item.xml

---------------------

 

```

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="match_parent"

    android:layout_height="100dp"

    android:orientation="horizontal">

 

    <CheckBox

        android:id="@+id/cb_group"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_marginBottom="30dp"

        android:layout_marginLeft="10dp"

        android:layout_marginTop="30dp"

        android:focusable="false" />

 

    <ImageView

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_marginLeft="10dp"

        android:layout_marginTop="30dp"

        android:background="@drawable/title" />

 

    <TextView

        android:id="@+id/gou_dian"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_marginLeft="20dp"

        android:layout_marginTop="30dp"

        android:text="商家11 >"

        android:textSize="20sp" />

</LinearLayout>

```

 

> detail_rlv_adapter_item.xml

-----------------------------

 

```

<?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"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:orientation="vertical">

 

    <com.facebook.drawee.view.SimpleDraweeView

        android:id="@+id/detail_adapter_sdv"

        android:layout_width="match_parent"

        android:layout_height="300dp"

        app:placeholderImage="@mipmap/ic_launcher" />

 

    <RelativeLayout

        android:layout_width="match_parent"

        android:layout_height="wrap_content">

 

        <LinearLayout

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:orientation="vertical">

 

            <TextView

                android:id="@+id/tv_detail_title"

                android:layout_width="match_parent"

                android:layout_height="wrap_content"

                android:layout_margin="5dp"

                android:text="费卡机发电电费卡机发电电费卡机发电" />

 

            <TextView

                android:id="@+id/tv_detail_price"

                android:layout_width="match_parent"

                android:layout_height="wrap_content"

                android:layout_margin="5dp"

                android:text="¥1321.0"

                android:textColor="#E2791E" />

 

            <TextView

                android:id="@+id/tv_detail_sj"

                android:layout_width="match_parent"

                android:layout_height="wrap_content"

                android:layout_margin="5dp"

                android:text="我是商家11" />

        </LinearLayout>

 

        <ImageView

            android:layout_width="wrap_content"

            android:layout_height="70dp"

            android:layout_alignParentRight="true"

            android:src="@drawable/fenxiang" />

    </RelativeLayout>

 

</LinearLayout>

```

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值