Android 双RecyclerView嵌套实现购物车逻辑

下面代码通过Recyclerview嵌套Recyclerview实现了购物车的全选、反选和点选。先来看看效果图吧!
先来看看效果图吧,看看是不是你想要的:
左边是空的购物车页面,右边是添加入数据的购物车;

首先来主页面xml布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <RelativeLayout
       android:layout_width="match_parent"
       android:layout_height="58dp"
       android:id="@+id/toolbar_tou"
        android:background="#fff"
       android:layout_alignParentTop="true"
       android:layout_alignParentStart="true">
       <TextView
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text="购物车"
           android:id="@+id/toolbar_text"
           android:textSize="18sp"
           android:textColor="#1b1919"
           android:layout_centerInParent="true"
           />
       <TextView
           android:visibility="gone"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:id="@+id/bianji"
           android:text="编辑"
           android:textSize="16sp"
           android:textColor="#1b1919"
           android:layout_centerVertical="true"
           android:layout_marginEnd="6dp"
           android:layout_toLeftOf="@+id/xiaoxi"
           />
       <ImageView
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:id="@+id/xiaoxi"
           android:background="@drawable/manages"
           android:layout_centerVertical="true"
           android:layout_alignParentRight="true"
           android:layout_marginRight="8dp"
           />
   </RelativeLayout>
    <TextView
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:id="@+id/toolbar_xian"
        android:background="#ddd"
        android:layout_below="@+id/toolbar_tou"
        />
    <com.jwenfeng.library.pulltorefresh.PullToRefreshLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/pull_cars"
        android:layout_below="@id/toolbar_xian"
        >
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/toolbar_xian"
        >
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#fff"
            >
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="34dp"
        android:id="@+id/login_zt"
        android:background="#fff"
        >
        <Button
            android:layout_width="75dp"
            android:layout_height="23dp"
            android:text="登录"
            android:id="@+id/login_cars_btn"
            android:layout_centerVertical="true"
            android:background="@drawable/cars_btn_two3"
            android:layout_marginLeft="20dp"
            />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/login_text"
            android:text="登录后同步电脑与手机购物车中的商品"
            android:textSize="16sp"
            android:layout_centerVertical="true"
            android:layout_toRightOf="@id/login_cars_btn"
            android:textColor="#a1a0a0"
            android:layout_marginLeft="10dp"
            />
    </RelativeLayout>
    <TextView
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:id="@+id/xian4"
        android:background="#ddd"
        android:layout_below="@id/login_zt"
        />
     <RelativeLayout
         android:layout_width="match_parent"
         android:layout_height="110dp"
         android:layout_below="@+id/xian4"
         android:id="@+id/cars_login"
         android:background="#fff"
         >
         <ImageView
             android:layout_width="50dp"
             android:layout_height="38dp"
             android:id="@+id/cars_icons"
             android:background="@mipmap/cars_icons"
             android:layout_alignParentTop="true"
             android:layout_alignParentStart="true"
             android:layout_marginStart="103dp"
             android:layout_marginTop="10dp" />
         <TextView
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:id="@+id/cars_kong"
             android:text="购物车是空的"
             android:textSize="20sp"
             android:textColor="#a1a0a0"
             android:layout_marginStart="14dp"
             android:layout_marginBottom="6dp"
             android:layout_alignBottom="@+id/cars_icons"
             android:layout_toEndOf="@+id/cars_icons" />
         <Button
             android:layout_width="85dp"
             android:layout_height="28dp"
             android:id="@+id/guang"
             android:background="@drawable/cars_btn_two"
             android:layout_below="@id/cars_icons"
             android:layout_marginLeft="100dp"
             android:layout_marginTop="20dp"
             android:text="逛逛秒杀"
             />
         <Button
             android:layout_width="85dp"
             android:layout_height="28dp"
             android:id="@+id/kan_guan"
             android:background="@drawable/cars_btn_two2"
             android:layout_below="@id/cars_icons"
             android:layout_toRightOf="@id/guang"
             android:layout_marginTop="20dp"
             android:layout_marginLeft="30dp"
             android:text="看看关注"
             android:textColor="#f00"
             />
     </RelativeLayout>
    <TextView
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:id="@+id/zt_xians"
        android:layout_below="@id/cars_login"
        android:background="#ddd"
        />
      <android.support.v7.widget.RecyclerView
          android:visibility="gone"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:id="@+id/recy_father"
          android:background="#fff"
          android:layout_below="@id/zt_xians"
          >
      </android.support.v7.widget.RecyclerView>
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="38dp"
        android:background="@drawable/tese"
        android:id="@+id/weini_icons"
        android:layout_below="@+id/recy_father"
        />
    <com.example.zhangtao.jing_east.My_Recy
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/recy_weini"
        android:layout_below="@id/weini_icons"
        ></com.example.zhangtao.jing_east.My_Recy>
        </RelativeLayout>
    </ScrollView>
    </com.jwenfeng.library.pulltorefresh.PullToRefreshLayout>
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:id="@+id/foots_view"
        android:background="#fff"
        android:layout_alignParentBottom="true"
        android:layout_alignParentStart="true">
        <CheckBox
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/quan_che"
            android:text="全选"
            android:layout_centerVertical="true"
            android:layout_marginLeft="8dp"
            />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/price_zong"
            android:text="总价:0.0"
            android:textSize="16sp"
            android:textColor="#000"
            android:layout_toRightOf="@+id/quan_che"
            android:layout_marginLeft="15dp"
            android:layout_marginTop="5dp"
            />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/shop_zong"
            android:text="共0件商品"
            android:textSize="14sp"
            android:textColor="#000"
            android:layout_toRightOf="@+id/quan_che"
            android:layout_below="@id/price_zong"
            android:layout_marginLeft="15dp"
            />
        <Button
            android:layout_width="90dp"
            android:layout_height="35dp"
            android:text="去结算"
            android:id="@+id/price_btn"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_marginRight="20dp"
            android:background="@drawable/shopcar_btn"
            />
        <Button
            android:visibility="invisible"
            android:layout_width="80dp"
            android:layout_height="35dp"
            android:text="分享"
            android:id="@+id/fen_btn"
            android:background="@drawable/shopcar_btn1"
            android:layout_toRightOf="@id/quan_che"
            android:layout_centerVertical="true"
            android:layo
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值