andriod——加入购物车

本文详细介绍了在Android应用中实现购物车功能的过程,包括使用RvAdapter、定义AddCartBean和GoosBean数据模型,结合EventBus的MessageEvent和PriceAndCountEvent事件,以及在AddCartModel和MainModel中处理业务逻辑,利用Api接口和OnNetListener进行网络请求,MainPresenter作为视图和模型间的桥梁,同时在IMainActivity和MainActivity中展示UI,涉及activity_main.xml、activity_other.xml和myview.xml等布局文件。
摘要由CSDN通过智能技术生成


adapter——RvAdapter

package com.example.goodscar.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.TextView;

import com.example.goodscar.MyView;
import com.example.goodscar.R;
import com.example.goodscar.bean.GoosBean;
import com.example.goodscar.eventbusevent.MessageEvent;
import com.example.goodscar.eventbusevent.PriceAndCountEvent;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

public class RvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context context;
    private List<GoosBean.DataBean.DatasBean> list;
    private List<String> pidList = new ArrayList<>();

    public RvAdapter(Context context, List<GoosBean.DataBean.DatasBean> list) {
        this.context = context;
        this.list = list;
    }



    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.child, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        final GoosBean.DataBean.DatasBean datasBean = list.get(position);
        final MyViewHolder myViewHolder = (MyViewHolder) holder;
        myViewHolder.cbChild.setChecked(datasBean.isChecked());
        myViewHolder.tv_tel.setText(datasBean.getType_name());
        myViewHolder.tv_content.setText(datasBean.getMsg());
        myViewHolder.tv_time.setText(datasBean.getAdd_time());
        myViewHolder.tv_price.setText(datasBean.getPrice() + "");
        myViewHolder.myView.setNum(datasBean.getNum() + "");
        //checkbox点击事件
        myViewHolder.cbChild.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                datasBean.setChecked(myViewHolder.cbChild.isChecked());
                PriceAndCountEvent compute = compute();
                EventBus.getDefault().post(compute);
                if (myViewHolder.cbChild.isChecked()) {
                    pidList.add(datasBean.getCart_id());
                    if (isAllCbSelected()) {
                        //改变"全选"状态
                        changeAllCbState(true);
                    }
                } else {
                    pidList.remove(datasBean.getCart_id());
                    changeAllCbState(false);
                }
                notifyDataSetChanged();

            }
        });

        myViewHolder.myView.setAddClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int num = myViewHolder.myView.getNum();
                num++;
                datasBean.setNum(num);
                if (myViewHolder.cbChild.isChecked()) {
                    EventBus.getDefault().post(compute());
                }
                notifyDataSetChanged();
            }
        });
        myViewHolder.myView.setDelClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int num = myViewHolder.myView.getNum();
                if (num == 1) {
                    return;
                }
                num--;
                datasBean.setNum(num);
                if (myViewHolder.cbChild.isChecked()) {
                    EventBus.getDefault().post(compute());
                }
                notifyDataSetChanged();
            }
        });

        myViewHolder.tv_del.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                list.remove(position);
                EventBus.getDefault().post(compute());
                notifyDataSetChanged();
            }
        });

    }

    /**
     * 改变全选的状态
     *
     * @param flag
     */
    private void changeAllCbState(boolean flag) {
        MessageEvent messageEvent = new MessageEvent();
        messageEvent.setChecked(flag);
        EventBus.getDefault().post(messageEvent);
    }

    private boolean isAllCbSelected() {
        for (int i = 0; i < list.size(); i++) {
            GoosBean.DataBean.DatasBean datasBean = list.get(i);
            if (!datasBean.isChecked()) {
                return false;
            }
        }
        return true;
    }

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

    class MyViewHolder extends RecyclerView.ViewHolder {

        private final CheckBox cbChild;
        private final TextView tv_tel;
        private final TextView tv_content;
        private final TextView tv_time;
        private final TextView tv_price;
        private MyView myView;
        private final TextView tv_del;

        public MyViewHolder(View itemView) {
            super(itemView);
            cbChild = itemView.findViewById(R.id.cb_child);
            tv_tel = itemView.findViewById(R.id.tv_tel);
            tv_content = itemView.findViewById(R.id.tv_content);
            tv_time = itemView.findViewById(R.id.tv_time);
            tv_price = itemView.findViewById(R.id.tv_pri);
            tv_del = itemView.findViewById(R.id.tv_del);
            myView = itemView.findViewById(R.id.mv);
        }
    }

    private PriceAndCountEvent compute() {
        int price = 0;
        int count = 0;
        for (int i = 0; i < list.size(); i++) {
            GoosBean.DataBean.DatasBean datasBean = list.get(i);
            if (datasBean.isChecked()) {
                price += datasBean.getPrice() * datasBean.getNum();
                count += datasBean.getNum();
            }
        }
        PriceAndCountEvent priceAndCountEvent = new PriceAndCountEvent();
        priceAndCountEvent.setPrice(price);
        priceAndCountEvent.setCount(count);
        return priceAndCountEvent;
    }

    public void allSelect(boolean flag) {
        for (int i = 0; i < list.size(); i++) {
            GoosBean.DataBean.DatasBean datasBean = list.get(i);
            datasBean.setChecked(flag);
        }
        EventBus.getDefault().post(compute());
        notifyDataSetChanged();
    }

    public List<String> getPidList() {
        return pidList;
    }
}


bean——AddCartBean

package com.example.goodscar.bean;

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


bean——GoosBean

    public static final String url = "http://result.eolinker.com/iYXEPGn4e9c6dafce6e5cdd23287d2bb136ee7e9194d3e9?uri=evaluation";


eventbusevent——MessageEvent

package com.example.goodscar.eventbusevent;

public class MessageEvent {
    private boolean checked;

    public boolean isChecked() {
        return checked;
    }

    public void setChecked(boolean checked) {
        this.checked = checked;
    }
}


eventbusevent——PriceAndCountEvent

package com.example.goodscar.eventbusevent;

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


mode——AddCartModel

package com.example.goodscar.mode;

import android.os.Handler;
import android.os.Looper;

import com.example.goodscar.bean.AddCartBean;
import com.example.goodscar.net.Api;
import com.example.goodscar.net.HttpUtils;
import com.example.goodscar.net.OnNetListener;
import com.google.gson.Gson;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;

public class AddCartModel {
    private Handler handler = new Handler(Looper.getMainLooper());

    public void addCart(String uid, String pid, final OnNetListener<AddCartBean> onNetListener) {
        String url = String.format(Api.ADD_CART, uid, pid);
        HttpUtils.getHttpUtils().doGet(url, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String string = response.body().string();
                final AddCartBean addCartBean = new Gson().fromJson(string, AddCartBean.class);
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        onNetListener.onSuccess(addCartBean);
                    }
                });
            }
        });
    }
}

mode——IMainModel

package com.example.goodscar.mode;

import com.example.goodscar.bean.GoosBean;
import com.example.goodscar.net.OnNetListener;

public interface IMainModel {
    public void getGoods(OnNetListener<GoosBean> onNetListener);
}


mode——MainModel

package com.example.goodscar.mode;

import android.os.Handler;
import android.os.Looper;

import com.example.goodscar.bean.GoosBean;
import com.example.goodscar.net.Api;
import com.example.goodscar.net.HttpUtils;
import com.example.goodscar.net.OnNetListener;
import com.google.gson.Gson;

import java.io.IOException;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;

public class MainModel implements IMainModel {
    private Handler handler = new Handler(Looper.getMainLooper());


    public void getGoods(final OnNetListener<GoosBean> onNetListener) {
        HttpUtils.getHttpUtils().doGet(Api.url, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String string = response.body().string();
                final GoosBean goosBean = new Gson().fromJson(string, GoosBean.class);
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        onNetListener.onSuccess(goosBean);
                    }
                });
            }
        });
    }
}


net——Api

package com.example.goodscar.net;

public interface Api {
    public static final String url = "http://result.eolinker.com/iYXEPGn4e9c6dafce6e5cdd23287d2bb136ee7e9194d3e9?uri=evaluation";
    public static final String ADD_CART = "http://120.27.23.105/product/addCart?uid=%s&pid=%s";
    public static final String SEARCH_CART = "http://120.27.23.105/product/getCarts?uid=%s";
}

net——HttpUtils

package com.example.goodscar.net;

import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.logging.HttpLoggingInterceptor;

public class HttpUtils {
    private static volatile HttpUtils httpUtils;
    private final OkHttpClient client;

    private HttpUtils() {
        HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
        logging.setLevel(HttpLoggingInterceptor.Level.BODY);
        client = new OkHttpClient.Builder()
                .addInterceptor(logging)
                .build();
    }

    public static HttpUtils getHttpUtils() {
        if (httpUtils == null) {
            synchronized (HttpUtils.class) {
                if (httpUtils == null) {
                    httpUtils = new HttpUtils();
                }
            }
        }
        return httpUtils;
    }

    /**
     * GET请求
     *
     * @param url
     * @param callback
     */
    public void doGet(String url, Callback callback) {
        Request request = new Request.Builder().url(url).build();
        client.newCall(request).enqueue(callback);
    }
}


net——OnNetListener

public interface OnNetListener<T> {
    public void onSuccess(T t);

    public void onFailure(Exception e);
}

presenter——AddCartPresenter

package com.example.goodscar.presenter;


import com.example.goodscar.MainActivity;
import com.example.goodscar.bean.AddCartBean;
import com.example.goodscar.mode.AddCartModel;
import com.example.goodscar.net.OnNetListener;

public class AddCartPresenter {

    private AddCartModel addCartModel;
    private MainActivity otherActivity;

    public AddCartPresenter(MainActivity ac) {
        this.otherActivity = ac;
        this.addCartModel = new AddCartModel();
    }

    public void addCart(String uid, String pid) {
        addCartModel.addCart(uid, pid, new OnNetListener<AddCartBean>() {


            @Override
            public void onSuccess(AddCartBean addCartBean) {
                otherActivity.show(addCartBean.getMsg());
            }

            @Override
            public void onFailure(Exception e) {

            }
        });
    }


}


presenter——MainPresenter

package com.example.goodscar.presenter;


import com.example.goodscar.bean.GoosBean;
import com.example.goodscar.mode.IMainModel;
import com.example.goodscar.mode.MainModel;
import com.example.goodscar.net.OnNetListener;
import com.example.goodscar.view.IMainActivity;

import java.util.ArrayList;
import java.util.List;

public class MainPresenter {

    private final IMainModel imainModel;
    private final IMainActivity iMainActivity;

    public MainPresenter(IMainActivity iMainActivity) {
        this.iMainActivity = iMainActivity;
        imainModel = new MainModel();
    }

    public void getGoods2() {
        imainModel.getGoods(new OnNetListener<GoosBean>() {
            @Override
            public void onSuccess(GoosBean goosBean) {
                List<GoosBean.DataBean.DatasBean> list = new ArrayList<GoosBean.DataBean.DatasBean>();
                List<GoosBean.DataBean> data = goosBean.getData();
                for (int i = 0; i < data.size(); i++) {
                    List<GoosBean.DataBean.DatasBean> datas = data.get(i).getDatas();
                    list.addAll(datas);
                }
                iMainActivity.showList(list);
            }

            @Override
            public void onFailure(Exception e) {

            }
        });
    }

    public void getGoods() {
        imainModel.getGoods(new OnNetListener<GoosBean>() {
            @Override
            public void onSuccess(GoosBean goosBean) {
                //List<GoosBean.DataBean> groupList, List<List<GoosBean.DataBean.DatasBean>> childList
                List<GoosBean.DataBean> dataBean = goosBean.getData();
                List<List<GoosBean.DataBean.DatasBean>> childList = new ArrayList<List<GoosBean.DataBean.DatasBean>>();
                for (int i = 0; i < dataBean.size(); i++) {
                    List<GoosBean.DataBean.DatasBean> datas = dataBean.get(i).getDatas();
                    childList.add(datas);
                }
                iMainActivity.showList(dataBean, childList);
            }

            @Override
            public void onFailure(Exception e) {

            }
        });

    }

}


view——IMainActivity

package com.example.goodscar.view;

import com.example.goodscar.bean.GoosBean;

import java.util.List;

public interface IMainActivity {
    public void showList(List<GoosBean.DataBean> groupList, List<List<GoosBean.DataBean.DatasBean>> childList);
    public void showList(List<GoosBean.DataBean.DatasBean> list);
}


MainActivity

package com.example.goodscar;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;
import android.widget.Toast;

import com.example.goodscar.adapter.RvAdapter;
import com.example.goodscar.bean.GoosBean;
import com.example.goodscar.eventbusevent.MessageEvent;
import com.example.goodscar.eventbusevent.PriceAndCountEvent;
import com.example.goodscar.net.Api;
import com.example.goodscar.net.HttpUtils;
import com.example.goodscar.presenter.AddCartPresenter;
import com.example.goodscar.presenter.MainPresenter;
import com.example.goodscar.view.IMainActivity;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import java.io.IOException;
import java.util.List;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;

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

    private RecyclerView mRv;
    private CheckBox mCheckbox2;
    /**
     * 0
     */
    private TextView mTvPrice;
    /**
     * 结算(0)
     */
    private TextView mTvNum;
    private MainPresenter mainPresenter;
    private AddCartPresenter addCartPresenter;
    private RvAdapter myAdapter;
    /**
     * 查询购物车
     */
    private Button mBtSearch;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_other);
        EventBus.getDefault().register(this);
        mainPresenter = new MainPresenter(this);
        addCartPresenter = new AddCartPresenter(this);
        initView();
        mRv.setLayoutManager(new LinearLayoutManager(this));
        //先请求接口数据
        mainPresenter.getGoods2();
        mCheckbox2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                myAdapter.allSelect(mCheckbox2.isChecked());
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    @Subscribe
    public void onMessageEvent(MessageEvent event) {
        mCheckbox2.setChecked(event.isChecked());
    }

    @Subscribe
    public void onMessageEvent(PriceAndCountEvent event) {
        mTvNum.setText("加入购物车(" + event.getCount() + ")");
        mTvPrice.setText(event.getPrice() + "");
    }

    private void initView() {
        mRv = (RecyclerView) findViewById(R.id.rv);
        mCheckbox2 = (CheckBox) findViewById(R.id.checkbox2);
        mTvPrice = (TextView) findViewById(R.id.tv_price);
        mTvNum = (TextView) findViewById(R.id.tv_num);
        mTvNum.setOnClickListener(this);
        mBtSearch = (Button) findViewById(R.id.bt_search);
        mBtSearch.setOnClickListener(this);
    }

    //是给MainActivity用的方法,此处不必管它
    @Override
    public void showList(List<GoosBean.DataBean> groupList, List<List<GoosBean.DataBean.DatasBean>> childList) {

    }

    @Override
    public void showList(List<GoosBean.DataBean.DatasBean> list) {
        myAdapter = new RvAdapter(this, list);
        mRv.setAdapter(myAdapter);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            default:
                break;
            case R.id.tv_num:
                //加入购物车
                //获取集合里的pid
                if (myAdapter != null) {
                    List<String> pidList = myAdapter.getPidList();
                    for (int i = 0; i < pidList.size(); i++) {
                        addCartPresenter.addCart("71", pidList.get(i));
                    }
                }
                break;
            case R.id.bt_search:
                String url = String.format(Api.SEARCH_CART, "71");
                HttpUtils.getHttpUtils().doGet(url, new Callback() {
                    @Override
                    public void onFailure(Call call, IOException e) {

                    }


                    @Override
                    public void onResponse(Call call, Response response) throws IOException {
                        String string = response.body().string();
                    }
                });
                break;
        }
    }

    public void show(String msg) {
        Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show();
    }
}

MyView

package com.example.goodscar;

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


public class MyView extends LinearLayout {

    private ImageView iv_add;
    private ImageView iv_del;
    private TextView tv_num;

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

    public MyView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        View view = LayoutInflater.from(context).inflate(R.layout.myview, this);
        iv_add = findViewById(R.id.iv_add);
        iv_del = findViewById(R.id.iv_del);
        tv_num = findViewById(R.id.tv_num);
    }

    public void setAddClickListener(OnClickListener onClickListener) {
        iv_add.setOnClickListener(onClickListener);
    }

    public void setDelClickListener(OnClickListener onClickListener) {
        iv_del.setOnClickListener(onClickListener);
    }

    public void setNum(String num) {
        tv_num.setText(num);
    }

    public int getNum() {
        String num = tv_num.getText().toString();
        return Integer.parseInt(num);
    }
}


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

    <TextView
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:background="#990000ff"
        android:gravity="center"
        android:text="购物车"
        android:textColor="#ff3660"
        android:textSize="25sp" />

    <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="50dp"
        android:layout_alignParentBottom="true"
        android:background="@android:color/white"
        android:gravity="center_vertical">

        <CheckBox
            android:id="@+id/checkbox2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginLeft="10dp"
            android:focusable="false" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="50dp"
            android:layout_centerVertical="true"
            android:layout_marginLeft="10dp"
            android:layout_toRightOf="@+id/checkbox2"
            android:gravity="center_vertical"
            android:text="全选"
            android:textSize="20sp" />

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

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:text="合计 :" />


            <TextView
                android:id="@+id/tv_price"
                android:layout_width="wrap_content"
                android:layout_height="50dp"
                android:layout_marginLeft="10dp"
                android:paddingRight="10dp"
                android:text="0"
                android:textColor="@android:color/holo_red_light" />


            <TextView
                android:id="@+id/tv_num"
                android:layout_width="wrap_content"
                android:layout_height="50dp"
                android:background="@android:color/holo_red_dark"
                android:gravity="center"
                android:padding="10dp"
                android:text="结算(0)"
                android:textColor="@android:color/white" />
        </LinearLayout>
    </RelativeLayout>


</LinearLayout>


activity_other.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">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:background="#990000ff"
        android:gravity="center"
        android:text="购物车"
        android:textColor="#ff3660"
        android:textSize="25sp" />

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

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_alignParentBottom="true"
        android:background="@android:color/white"
        android:gravity="center_vertical">

        <CheckBox
            android:id="@+id/checkbox2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginLeft="10dp"
            android:focusable="false" />

        <Button
            android:id="@+id/bt_search"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="查询购物车" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="50dp"
            android:layout_centerVertical="true"
            android:layout_marginLeft="10dp"
            android:layout_toRightOf="@+id/checkbox2"
            android:gravity="center_vertical"
            android:text="全选"
            android:textSize="20sp" />

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

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:text="合计 :" />


            <TextView
                android:id="@+id/tv_price"
                android:layout_width="wrap_content"
                android:layout_height="50dp"
                android:layout_marginLeft="10dp"
                android:paddingRight="10dp"
                android:text="0"
                android:textColor="@android:color/holo_red_light" />


            <TextView
                android:id="@+id/tv_num"
                android:layout_width="wrap_content"
                android:layout_height="50dp"
                android:background="@android:color/holo_red_dark"
                android:gravity="center"
                android:padding="10dp"
                android:text="加入购物车(0)"
                android:textColor="@android:color/white" />
        </LinearLayout>
    </RelativeLayout>
</LinearLayout>

child.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="wrap_content"
    android:background="@android:color/darker_gray"
    android:gravity="center_vertical"
    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="40dp"
        android:layout_marginTop="30dp"
        android:focusable="false" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <TextView
            android:id="@+id/tv_tel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:text="iphone6" />

        <TextView
            android:id="@+id/tv_content"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:text="什么手机" />

        <TextView
            android:id="@+id/tv_time"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:text="2016-12-10" />
    </LinearLayout>

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

        <TextView
            android:id="@+id/tv_pri"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"

            android:text="¥3000.00" />

        <com.example.goodscar.MyView
            android:id="@+id/mv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

        </com.example.goodscar.MyView>
    </LinearLayout>

    <TextView
        android:id="@+id/tv_del"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="删除" />
</LinearLayout>


myview.xml

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


    <ImageView
        android:id="@+id/iv_del"
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:src="@drawable/shopcart_minus_grey" />

    <TextView
        android:id="@+id/tv_num"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:background="@drawable/shopcart_add_btn"
        android:paddingBottom="2dp"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        android:paddingTop="2dp"
        android:text="1" />

    <ImageView
        android:id="@+id/iv_add"
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:layout_marginLeft="5dp"
        android:src="@drawable/shopcart_add_red" />

</LinearLayout>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值