購物車兩個Adaper,可以刪除,全選反選,數量加減,通過RecycleView巢狀實現
阿新 • • 發佈:2018-12-21
1activity_main.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" android:focusableInTouchMode="true" android:focusable="true" tools:context=".activity.MainActivity"> <RelativeLayout android:id="@+id/lauout_top" android:layout_width="match_parent" android:layout_height="50dp" android:background="@color/design_default_color_primary" > <ImageView android:id="@+id/iv_back" android:layout_width="30dp" android:layout_height="30dp" android:background="@drawable/back" android:layout_centerVertical="true" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerInParent="true" android:text="購物車" android:textColor="#fff" android:textSize="20sp" /> </RelativeLayout> <!--中間的顯示商家的recycleview--> <android.support.v7.widget.RecyclerView android:id="@+id/recycle_view" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_above="@id/layput_buttom" android:layout_below="@id/lauout_top" /> <!--下面的全選--> <RelativeLayout android:id="@+id/layput_buttom" android:layout_width="match_parent" android:layout_height="50dp" android:layout_alignParentBottom="true" android:background="#ffffff" android:paddingLeft="10dp" > <RelativeLayout android:id="@+id/lauout_all" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" > <CheckBox android:id="@+id/all_check" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" /> <TextView android:id="@+id/text_all" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:text="全選/反選" android:layout_marginLeft="5dp" android:layout_toRightOf="@id/all_check" /> </RelativeLayout> <TextView android:id="@+id/all_price" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_marginLeft="5dp" android:layout_toRightOf="@id/lauout_all" android:text="合計:0.00" android:textColor="#222222" android:textSize="20sp" /> <RelativeLayout android:id="@+id/sum_price" android:layout_width="100dp" android:layout_height="match_parent" android:layout_alignParentRight="true" android:background="@color/colorPrimary" > <TextView android:id="@+id/sum_price_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="去結算(0)" android:textColor="#ffffff" /> </RelativeLayout> </RelativeLayout> </RelativeLayout>
2自定義加減器佈局
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:id="@+id/jian_car" android:layout_width="20dp" android:layout_height="20dp" android:layout_centerVertical="true" android:src="@drawable/ic_jian_name" /> <EditText android:id="@+id/edit_car" android:layout_width="50dp" android:layout_height="30dp" android:layout_centerVertical="true" android:layout_toRightOf="@id/jian_car" android:background="@drawable/edit_shape" android:gravity="center_horizontal" android:inputType="number" android:text="1" android:textSize="14sp" /> <ImageView android:id="@+id/add_car" android:layout_width="20dp" android:layout_height="20dp" android:layout_centerVertical="true" android:src="@drawable/ic_add_name" android:layout_toRightOf="@id/edit_car" /> </RelativeLayout>
3.展示商家的佈局(裡面有一個Recycleview是為了展示商品)
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:orientation="vertical" android:layout_height="wrap_content"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <CheckBox android:id="@+id/mearchant_check" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:layout_gravity="center" /> <TextView android:id="@+id/mearchant_text" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:textSize="20sp" android:text="商家" /> </LinearLayout> <android.support.v7.widget.RecyclerView android:id="@+id/mearchant_recycle" android:layout_width="match_parent" android:layout_height="match_parent"/> </LinearLayout>
4.展示商品的佈局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff">
<CheckBox
android:id="@+id/shop_check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp" />
<ImageView
android:id="@+id/shop_image"
android:layout_width="120dp"
android:layout_height="100dp"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="10dp"
android:layout_toRightOf="@id/shop_check" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_centerVertical="true"
android:layout_toRightOf="@id/shop_image">
<TextView
android:id="@+id/shop_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="2"
android:text="title"
android:textColor="#222222"
android:textSize="20sp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
>
<TextView
android:id="@+id/shop_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:textColor="#f00"
android:textSize="20sp"
android:text="price"
/>
<com.example.shoppingcart02.custom.CustomView
android:id="@+id/shop_custom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/shop_price"
android:layout_centerVertical="true"
android:layout_marginLeft="15dp"
/>
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
5.用於展示商家的介面卡
package com.example.shoppingcart02.adaper;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.OrientationHelper;
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.shoppingcart02.R;
import com.example.shoppingcart02.bean.ShopBean;
import java.util.ArrayList;
import java.util.List;
public class MearchantAdapaer extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private List<ShopBean.DataBean> mData;
private Context mContext;
public MearchantAdapaer(Context mContext) {
this.mContext = mContext;
mData = new ArrayList<>();
}
public void setmData(List<ShopBean.DataBean> datas){
mData.addAll(datas);
notifyDataSetChanged();
}
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(mContext).inflate(R.layout.merchant_item,viewGroup,false);
ViewHolderMearchant holderMearchant = new ViewHolderMearchant(view);
return holderMearchant;
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, final int i) {
final ViewHolderMearchant holderMearchant = (ViewHolderMearchant) viewHolder;
//設定商家
holderMearchant.mearchant_text.setText(mData.get(i).getSellerName());
final ShopAdaper shopAdaper = new ShopAdaper(mContext,mData.get(i).getList());
LinearLayoutManager layoutManager = new LinearLayoutManager(mContext);
layoutManager.setOrientation(OrientationHelper.VERTICAL);
holderMearchant.mearchant_recycle.setLayoutManager(layoutManager);
holderMearchant.mearchant_recycle.setAdapter(shopAdaper);
holderMearchant.mearchant_check.setChecked(mData.get(i).isCheck());
shopAdaper.setShopCallBack(new ShopAdaper.ShopCallBack() {
@Override
public void callBack() {
//從商品裡回調回來
if(mearchantCallBack!=null){
mearchantCallBack.callBack(mData);
}
List<ShopBean.DataBean.ListBean> list = mData.get(i).getList();
//建立一個臨時標誌位
boolean isAllCheck = true;
for (ShopBean.DataBean.ListBean bean:list){
if(!bean.isCheck()){
//只要有一個商品未選中,標誌位設定成false,並且跳出迴圈
isAllCheck = false;
break;
}
}
//重新整理商家狀態
holderMearchant.mearchant_check.setChecked(isAllCheck);
mData.get(i).setCheck(isAllCheck);
}
});
//監聽checkBox的點選事件
//目的是改變旗下所有商品的選中狀態
holderMearchant.mearchant_check.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//首先改變自己的標誌位
mData.get(i).setCheck(holderMearchant.mearchant_check.isChecked());
//呼叫產品adapter的方法,用來全選和反選
shopAdaper.selectOrRemoveAll(holderMearchant.mearchant_check.isChecked());
}
});
}
@Override
public int getItemCount() {
return mData.size();
}
class ViewHolderMearchant extends RecyclerView.ViewHolder{
public final CheckBox mearchant_check;
public final TextView mearchant_text;
public final RecyclerView mearchant_recycle;
public ViewHolderMearchant(@NonNull View itemView) {
super(itemView);
mearchant_check = itemView.findViewById(R.id.mearchant_check);
mearchant_text = itemView.findViewById(R.id.mearchant_text);
mearchant_recycle = itemView.findViewById(R.id.mearchant_recycle);
}
}
private MearchantCallBack mearchantCallBack;
public void setMearchantCallBack(MearchantCallBack mearchantCallBack){
this.mearchantCallBack = mearchantCallBack;
}
//定義介面
public interface MearchantCallBack{
void callBack(List<ShopBean.DataBean> list);
}
}
6.用於展示商品的介面卡
package com.example.shoppingcart02.adaper;
import android.content.Context;
import android.support.annotation.NonNull;
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.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.example.shoppingcart02.R;
import com.example.shoppingcart02.bean.ShopBean;
import com.example.shoppingcart02.custom.CustomView;
import java.util.List;
/**
* 商品
* */
public class ShopAdaper extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private Context mContext;
private List<ShopBean.DataBean.ListBean> mList;
public ShopAdaper(Context mContext, List<ShopBean.DataBean.ListBean> mList) {
this.mContext = mContext;
this.mList = mList;
}
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(mContext).inflate(R.layout.shop_item,viewGroup,false);
ViewHolderShop holderShop = new ViewHolderShop(view);
return holderShop;
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, final int i) {
ViewHolderShop holderShop = (ViewHolderShop) viewHolder;
String url = mList.get(i).getImages().split("\\|")[0].replace("https","http");
Glide.with(mContext).load(url).into(holderShop.shop_image);
holderShop.shop_title.setText(mList.get(i).getTitle());
holderShop.shop_price.setText("價格:"+mList.get(i).getPrice()+"元");
//根據我記錄的狀態,改變勾選
holderShop.shop_check.setChecked(mList.get(i).isCheck());
//新增商品的選中的監聽
holderShop.shop_check.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
//優選改變自己的狀態
mList.get(i).setCheck(isChecked);
//回撥
if(shopCallBack!=null){
shopCallBack.callBack();
}
}
});
//設定自定義view裡的edit
holderShop.shop_custom.setData(this,mList,i);
holderShop.shop_custom.setCustomCallBack(new CustomView.CustomCallBack() {
@Override
public void callBack() {
if(shopCallBack!=null){
shopCallBack.callBack();
}
}
});
}
@Override
public int getItemCount() {
return mList.size();
}
class ViewHolderShop extends RecyclerView.ViewHolder{
public final ImageView shop_image;
public final TextView shop_title;
public final TextView shop_price;
public final CheckBox shop_check;
public final CustomView shop_custom;
public ViewHolderShop(@NonNull View itemView) {
super(itemView);
shop_check = itemView.findViewById(R.id.shop_check);
shop_custom = itemView.findViewById(R.id.shop_custom);
shop_image = itemView.findViewById(R.id.shop_image);
shop_price = itemView.findViewById(R.id.shop_price);
shop_title = itemView.findViewById(R.id.shop_title);
}
}
/**
* 在我們子商品的adapter中,修改子商品的全選和反選
*
* @param isSelectAll
*/
public void selectOrRemoveAll(boolean isSelectAll){
for(ShopBean.DataBean.ListBean listBean:mList){
listBean.setCheck(isSelectAll);
}
notifyDataSetChanged();
}
private ShopCallBack shopCallBack;
public void setShopCallBack(ShopCallBack shopCallBack){
this.shopCallBack = shopCallBack;
}
//定義介面
public interface ShopCallBack{
void callBack();
}
}
7.自定義加減器的view頁面
package com.example.shoppingcart02.custom;
import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.Toast;
import com.example.shoppingcart02.adaper.ShopAdaper;
import com.example.shoppingcart02.bean.ShopBean;
import com.example.shoppingcart02.R;
import java.util.ArrayList;
import java.util.List;
/**
* 加減數量
*/
public class CustomView extends RelativeLayout implements View.OnClickListener {
private ImageView add;
private ImageView jian;
private EditText editText;
public CustomView(Context context) {
super(context);
init(context);
}
public CustomView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
public CustomView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context);
}
private Context mContext;
private void init(Context context) {
mContext = context;
View view = View.inflate(mContext, R.layout.custom_item, null);
add = view.findViewById(R.id.add_car);
jian = view.findViewById(R.id.jian_car);
editText = view.findViewById(R.id.edit_car);
add.setOnClickListener(this);
jian.setOnClickListener(this);
addView(view);
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
try {
num = Integer.valueOf(s.toString());
list.get(position).setNum(num);
}catch (Exception e){
list.get(position).setNum(1);
}
if(customCallBack!=null){
customCallBack.callBack();
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
}
private int num;
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.add_car:
num++;
editText.setText(num + "");
list.get(position).setNum(num);
if(customCallBack!=null){
customCallBack.callBack();
}
shopAdaper.notifyItemChanged(position);
break;
case R.id.jian_car:
if (num > 1) {
num--;
} else {
Toast.makeText(mContext, "不能在減了", Toast.LENGTH_SHORT).show();
}
editText.setText(num + "");
list.get(position).setNum(num);
if(customCallBack!=null){
customCallBack.callBack();
}
shopAdaper.notifyItemChanged(position);
break;
default:
break;
}
}
//傳遞資料
private List<ShopBean.DataBean.ListBean> list = new ArrayList<>();
private int position;
private ShopAdaper shopAdaper;
public void setData(ShopAdaper shopAdaper, List<ShopBean.DataBean.ListBean> list, int i) {
this.list = list;
this.shopAdaper = shopAdaper;
position = i;
num = list.get(i).getNum();
editText.setText(num + "");
}
private CustomCallBack customCallBack;
public void setCustomCallBack(CustomCallBack customCallBack) {
this.customCallBack = customCallBack;
}
//定義介面
public interface CustomCallBack {
void callBack();
}
}
8.bean類(裡面寫一個boolean型別的值)
package com.example.shoppingcart02.bean;
import java.util.List;
public class ShopBean {
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 {
private String sellerName;
private String sellerid;
private List<ListBean> list;
private boolean isCheck;
public boolean isCheck() {
return isCheck;
}
public void setCheck(boolean check) {
isCheck = check;
}
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 {
private double bargainPrice;
private String createtime;
private String detailUrl;
private String images;
private int num;
private int pid;
private double price;
private int pscid;
private int selected;
private int sellerid;
private String subhead;
private String title;
private boolean isCheck;
public boolean isCheck() {
return isCheck;
}
public void setCheck(boolean check) {
isCheck = check;
}
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;
}
}
}
}
9.MainActivity頁面
package com.example.shoppingcart02.activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.CheckBox;
import android.widget.TextView;
import android.widget.Toast;
import com.example.shoppingcart02.R;
import com.example.shoppingcart02.adaper.MearchantAdapaer;
import com.example.shoppingcart02.api.Apis;
import com.example.shoppingcart02.bean.ShopBean;
import com.example.shoppingcart02.presenter.PresenterImpl;
import com.example.shoppingcart02.view.Iview;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class MainActivity extends AppCompatActivity implements Iview,View.OnClickListener {
private PresenterImpl presenter;
private List<ShopBean.DataBean> mList;
private CheckBox all_check;
private TextView all_price;
private TextView sum_price_text;
private RecyclerView recycle_view;
private MearchantAdapaer adapaer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
presenter = new PresenterImpl(this);
initView();
initData();
}
private void initData() {
Map<String,String> map = new HashMap<>();
map.put("uid","71");
presenter.startRequest(Apis.URL_SHOPP_CART,map,ShopBean.class);
}
private void initView() {
//獲取資源id
all_check = findViewById(R.id.all_check);
all_price = findViewById(R.id.all_price);
sum_price_text = findViewById(R.id.sum_price_text);
recycle_view = findViewById(R.id.recycle_view);
all_check.setOnClickListener(this);
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
layoutManager.setOrientation(OrientationHelper.VERTICAL);
recycle_view.setLayoutManager(layoutManager);
//建立介面卡
adapaer = new MearchantAdapaer(this);
recycle_view.setAdapter(adapaer);
adapaer.setMearchantCallBack(new MearchantAdapaer.MearchantCallBack() {
@Override
public void callBack(List<ShopBean.DataBean> list) {
//在這裡重新遍歷已經改狀態後的資料,
// 這裡不能break跳出,因為還需要計算後面點選商品的價格和數目,所以必須跑完整個迴圈
double totalPrice = 0;
//勾選商品的數量,不是該商品購買的數量
int num = 0;
//所有商品總數,和上面的數量做比對,如果兩者相等,則說明全選
int totalNum = 0;
for(int a = 0;a<list.size();a++){
//獲取商家裡商品
List<ShopBean.DataBean.ListBean> list1 = list.get(a).getList();
for(int i = 0;i<list1.size();i++){
totalNum = totalNum + list1.get(i).getNum();
//取選中的狀態
if(list1.get(i).isCheck()){
totalPrice = totalPrice+(list1.get(i).getPrice()*list1.get(i).getNum());
num = num + list1.get(i).getNum();
}
}
}
if(num<totalNum){
//不是全部選中
all_check.setChecked(false);
}else{
//全部選中
all_check.setChecked(true);
}
all_price.setText("合計:"+totalPrice+"元");
sum_price_text.setText("去結算("+num+")");
}
});
}
@Override
public void requestData(Object o) {
if(o instanceof ShopBean){
ShopBean bean = (ShopBean) o;
if(bean == null){
Toast.makeText(MainActivity.this,bean.getMsg(),Toast.LENGTH_SHORT).show();
}else{
mList = bean.getData();
if(mList!=null){
mList.remove(0);
adapaer.setmData(mList);
}
}
}
}
@Override
public void requestFail(Object o) {
if(o instanceof Exception){
Exception e = (Exception) o;
e.printStackTrace();
}
Toast.makeText(MainActivity.this,"網路請求錯誤",Toast.LENGTH_SHORT).show();
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.all_check:
checkSeller(all_check.isChecked());
adapaer.notifyDataSetChanged();
break;
default:
break;
}
}
@Override
protected void onDestroy() {
super.onDestroy();
presenter.onDetach();
}
/**
* 修改選中狀態,獲取價格和數量
*/
private void checkSeller(boolean b){
double totalPrice = 0;
int num = 0;
for(int a = 0;a<mList.size();a++){
//遍歷商家,改變狀態
ShopBean.DataBean dataBean = mList.get(a);
dataBean.setCheck(b);
List<ShopBean.DataBean.ListBean> list = mList.get(a).getList();
for(int i = 0;i<list.size();i++){
//遍歷商品,改變狀態
list.get(i).setCheck(b);
totalPrice = totalPrice+(list.get(i).getPrice()*list.get(i).getNum());
num = num + list.get(i).getNum();
}
}
if(b){
all_price.setText("合計:"+totalPrice+"元");
sum_price_text.setText("去結算("+num+")");
}else{
all_price.setText("合計:0.00元");
sum_price_text.setText("去結算(0)");
}
}
}
詳細程式碼請訪問一下連結
https://github.com/guoxinyu1995/yuekao/tree/master/shoppingcart02