//activity_main的布局
<RelativeLayout
android:id="@+id/bottom_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<CheckBox
android:id="@+id/Check_All"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="全选" />
<TextView
android:id="@+id/All_Price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="价格"/>
<TextView
android:id="@+id/Go_To_JS"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:text="去结算(0)" />
</RelativeLayout>
<ExpandableListView
android:id="@+id/Expand_View"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/bottom_layout" />
// MainActivity的页面
public class MainActivity extends AppCompatActivity implements IView {
private CheckBox Check_All;
private TextView All_Price;
private TextView Go_To_JS;
private RelativeLayout bottom_layout;
private ExpandableListView Expand_View;
private String mUrl=“http://www.wanandroid.com/tools/mockapi/6523/restaurant-list”;
ArrayList<User.DataBean> mList=new ArrayList<>();
private PerenerImpl perener;
private MyAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
perener = new PerenerImpl(this);
perener.startRequest(mUrl);
adapter = new MyAdapter(mList,this);
Expand_View.setAdapter(adapter);
}
@Override
public void setData(User data) {
mList.addAll(data.getData());
adapter.notifyDataSetChanged();
}
@Override
public void setError(String error) {
}
private void initView() {
Check_All = (CheckBox) findViewById(R.id.Check_All);
All_Price = (TextView) findViewById(R.id.All_Price);
Go_To_JS = (TextView) findViewById(R.id.Go_To_JS);
bottom_layout = (RelativeLayout) findViewById(R.id.bottom_layout);
Expand_View = (ExpandableListView) findViewById(R.id.Expand_View);
}
}
//二级列表子类的布局:chencbox 图片和商品介绍
<CheckBox
android:id="@+id/Child_Check_CB"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:id="@+id/Child_Icon"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginLeft="20dp"
android:scaleType="centerCrop"
android:src="@color/colorPrimary" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/Child_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="2"
android:text="商品标题" />
<TextView
android:id="@+id/Child_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="¥0.0" />
</LinearLayout>
//二级列表的父列表的布局:checkbox和textview
//加减的布局
<TextView
android:id="@+id/delete_tv"
android:layout_width="10dp"
android:layout_height="match_parent"
android:background="#ffffff"
android:gravity="center"
android:text="-"
android:textSize="16sp" />
<TextView
android:id="@+id/product_number_tv"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="2dp"
android:layout_weight="1"
android:background="#ffffff"
android:gravity="center"
android:text="1" />
<TextView
android:id="@+id/add_tv"
android:layout_width="10dp"
android:layout_height="match_parent"
android:layout_marginLeft="2dp"
android:background="#ffffff"
android:gravity="center"
android:text="+"
android:textSize="16sp" />