Android--ExpandableListview二级列表购物车功能实现

下面是购物车列表的简单实现

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
这是我所写的简单版MVP模式格式
这里写图片描述
导入相应的依赖
这里的依赖有很多请选择适合自己版本号的依赖

   compile 'com.github.bumptech.glide:glide:3.7.0'
    compile 'com.squareup.okhttp3:okhttp:3.9.0'
    compile 'com.google.code.gson:gson:2.8.1'
    compile 'com.jakewharton:butterknife:8.5.1'
    compile 'com.android.support:recyclerview-v7:26.0.0-alpha1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
    compile 'com.squareup.retrofit2:retrofit:2.3.0'//retrofit依赖
    compile 'com.squareup.retrofit2:converter-gson:2.3.0'//retrofit内部封装的GSON
    compile "io.reactivex.rxjava2:rxjava:2.1.7"
    compile "com.squareup.retrofit2:adapter-rxjava2:2.3.0"
    compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
    compile 'com.facebook.fresco:fresco:0.12.0'
    compile 'com.facebook.fresco:animated-base-support:0.12.0'
    compile 'com.facebook.fresco:animated-webp:0.12.0'
    compile 'com.facebook.fresco:webpsupport:0.12.0'

接下来需要“权限”

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

下面需要把values下的attrs属性添加上

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="AddDeleteView">
        <attr name="left_item" format="string"></attr>
        <attr name="right_item" format="string"></attr>
        <attr name="middle_item" format="string"></attr>
    </declare-styleable>
</resources>

这里是主界面的布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:gravity="center"
            android:text="购物车" />

        <TextView
            android:id="@+id/tv_bianji"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:text="编辑" />
    </RelativeLayout>

    <ExpandableListView
        android:id="@+id/exlist"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1">

    </ExpandableListView>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:orientation="horizontal"
        android:padding="10dp">

        <CheckBox
            android:id="@+id/check_all"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:gravity="center_vertical"
            android:text="全选"
            android:textSize="15dp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:gravity="center_vertical"
            android:text="总价:"
            android:textSize="15dp" />

        <TextView
            android:id="@+id/tv_zprice"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:gravity="center_vertical"
            android:text="0"
            android:textSize="15dp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:gravity="center_vertical"
            android:text="数量:"
            android:textSize="15dp" />

        <TextView
            android:id="@+id/tv_count"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_weight="1"
            android:gravity="center_vertical"
            android:text="0"
            android:textSize="15dp" />

        <Button
            android:id="@+id/btn_js"
            android:layout_width="80dp"
            android:layout_height="40dp"
            android:layout_gravity="right"
            android:background="#fc0109"
            android:text="结算"
            android:textSize="15dp" />
    </LinearLayout>
</LinearLayout>

这里是加减号以及数量的布局
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="-" />

    <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="+" />
</LinearLayout>

这里商品的子布局
gwc_goods_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:padding="10dp">

    <CheckBox
        android:id="@+id/check_gwc_goods"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_centerVertical="true"
        android:gravity="center_vertical" />

    <ImageView
        android:id="@+id/img_gwc_goods"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:src="@mipmap/ic_launcher" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值