功能基本和淘宝购物车一样,商品按照店铺分类显示,全选,反选,选中商品数量变化,总价随之变化。效果图
思路:店铺和商品都增加一个select属性,列表的CheckBox选择或未选中状态改变同时设置店铺和商品的select属性,每次CheckBox状态改变设置select的值等于cb.isChecked()
购物车页面布局文件activity_shopping_car
<?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=".ui.activity.ShoppingCarActivity">
<com.hjq.bar.TitleBar
android:id="@+id/titleBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:rightTitle="管理"
app:title="购物车" />
<com.qiyetec.flyingsnail.widget.HintLayout
android:id="@+id/hintLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<com.scwang.smartrefresh.layout.SmartRefreshLayout
android:id="@+id/smartRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.scwang.smartrefresh.layout.header.ClassicsHeader
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.scwang.smartrefresh.layout.SmartRefreshLayout>
</com.qiyetec.flyingsnail.widget.HintLayout>
<LinearLayout
android:id="@+id/ll_bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/ali_auth_space_10"
android:background="#fff"
android:gravity="center_vertical"
android:padding="15dp">
<CheckBox
android:id="@+id/cb_all"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/selector_checkbox_green"
android:text="全选" />
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1" />
<LinearLayout
android:id="@+id/ll"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="合计:"
android:textColor="#333"
android:textSize="15sp" />
<TextView
android:id="@+id/tv_total_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="¥0.00"
android:textColor="#DA3527"
android:textSize="24sp" />
<TextView
android:id="@+id/tv_buy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:background="@drawable/shape_red10"
android:paddingLeft="15dp"
android:paddingTop="5dp"
android:paddingRight="15dp"
android:paddingBottom="5dp"
android:text="结算"
android:textColor="#fff"
android:textSize="18sp" />
</LinearLayout>
<TextView
android:id="@+id/tv_del"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/shape_stroke_red15"
android:paddingLeft="15dp"
android:paddingTop="5dp"
android:paddingRight="15