//compile project(':mycartutils')
//XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.car.MainActivity">
<ExpandableListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"></ExpandableListView>
<RelativeLayout
android:id="@+id/a"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
>
<CheckBox
android:id="@+id/both"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="全选"
android:layout_centerVertical="true"
/>
<TextView
android:id="@+id/price"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="价格"
android:layout_centerInParent="true"
android:gravity="center"
/>
<TextView
android:id="@+id/num"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="价格"
android:layout_alignParentRight="true"
android:gravity="center"
/>
</RelativeLayout>
</RelativeLayout>
//MainActivity
package com.example.car;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.ExpandableListView;
import android.widget.TextView;
import com.bwie.mycartutils.bean.ChildBean;
import com.bwie.mycartutils.bean.GroupBean;
import com.bwie.mycartutils.utils.CartUtils;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
private ExpandableListView listView;
private TextView price,num;
private CheckBox both;
private List<GroupBean> glist=new ArrayList<>();
private List<List<ChildBean>> clists=new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView= (ExpandableListView) findViewById(R.id.listview);
price= (TextView) findViewById(R.id.price);
num= (TextView) findViewById(R.id.num);
both= (CheckBox) findViewById(R.id.both);
for(int i=0;i<2;i++){
glist.add(new GroupBean("商家"+i,false));
}
List<ChildBean> list1=new ArrayList<>();
for(int i=0;i<5;i++){
list1.add(new ChildBean("商品"+i,1+"","https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=594559231,2167829292&fm=27&gp=0.jpg",false,2));
}
List<ChildBean> list2=new ArrayList<>();
for(int i=0;i<3;i++){
list2.add(new ChildBean("商品"+i,1+"","https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=594559231,2167829292&fm=27&gp=0.jpg",false,2));
}
clists.add(list1);
clists.add(list2);
CartUtils.setCartData(this,glist,clists,listView,both,num,price);
}
}