效果图:
需要的依赖:
//retrofit2的依赖 compile 'com.squareup.retrofit2:retrofit:2.3.0' compile 'com.squareup.retrofit2:converter-gson:2.3.0' compile 'com.squareup.retrofit2:adapter-rxjava2:2.3.0' //rxJava2的依赖 compile 'io.reactivex.rxjava2:rxandroid:2.0.1' // Because RxAndroid releases are few and far between, it is recommended you also // explicitly depend on RxJava's latest version for bug fixes and new features. compile 'io.reactivex.rxjava2:rxjava:2.1.7' //拦截器的依赖 compile 'com.squareup.okhttp3:logging-interceptor:3.9.1' //recyclerview的依赖 implementation 'com.android.support:recyclerview-v7:26.1.0' //eventbus的依赖 compile 'org.greenrobot:eventbus:3.0.0' //Fresco的依赖 compile 'com.facebook.fresco:fresco:1.5.0'---------------------------------------XML布局----------------------------------
activity_cart.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" tools:context="com.example.erjicarts.view.activity.CartActivity"> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:layout_width="30dp" android:layout_height="30dp" android:layout_centerVertical="true" android:background="@drawable/leftjiantou" /> <TextView android:layout_width="match_parent" android:layout_height="40dp" android:gravity="center" android:text="购物车" android:textColor="#000" android:textSize="25sp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:layout_marginRight="20dp" android:text="编辑" /> </RelativeLayout> <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="70dp" android:layout_alignParentBottom="true" android:background="@android:color/white" android:gravity="center_vertical">cart_child_item.xml<CheckBox android:id="@+id/cb_All" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_marginLeft="10dp" android:checked="true" android:focusable="false" /><TextView android:id="@+id/tv_quxuan" android:layout_width="wrap_content" android:layout_height="50dp" android:layout_centerVertical="true" android:layout_marginLeft="10dp" android:layout_toRightOf="@+id/cb_All" android:gravity="center_vertical" android:text="全选" android:textSize="20sp" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/tv_quxuan" android:orientation="vertical"> <TextView android:id="@+id/tv_price" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:text="合计 :¥550.90" android:textSize="25dp" /> <TextView android:id="@+id/tv_carts_price" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:text="总额:582.70 立减:¥31.80" /> </LinearLayout> <TextView android:id="@+id/tv_num" android:layout_width="120dp" android:layout_height="match_parent" android:layout_alignParentRight="true" android:background="@android:color/holo_red_dark" android:gravity="center" android:padding="10dp" android:text="去结算(0)" android:textColor="@android:color/white" /> </RelativeLayout></LinearLayout>
<?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:id="@+id/del" android:layout_width="match_parent" android:layout_height="120dp" android:orientation="horizontal"> <CheckBox android:id="@+id/cb_child" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom=