2.首先先自定义一个二级列表
package com.example.jingdong.erji; import android.content.Context; import android.util.AttributeSet; import android.widget.ExpandableListView; /** * Created by huoxuebin on 2018/4/24. */ public class ErMyliebiao extends ExpandableListView { public ErMyliebiao(Context context) { super(context); } public ErMyliebiao(Context context, AttributeSet attrs) { super(context, attrs); } public ErMyliebiao(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int i = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, i); } } //添加购物车Bean类
package com.example.jingdong.bean; /** * Created by huoxuebin on 2018/4/25. */ public class AddShopBean { /** * msg : 加购成功 * code : 0 */ private String msg; private String code; public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } public String getCode() { return code; } public void setCode(String code) { this.code = code; } }
//查询购物车Bean类
package com.example.jingdong.bean; import java.util.List; /** * Created by huoxuebin on 2018/4/23. */ public class ShopBean { private String code; private String msg; private List<DataBean> data; public String getCode() { return code; } public void setCode(String code) { this.code = code; } public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } public List<DataBean> getData() { return data; } public void setData(List<DataBean> data) { this.data = data; } public static class DataBean { private String sellerName; private String sellerid; private List<ListBean> list; private boolean group_check; public boolean isGroup_check() { return group_check; } public void setGroup_check(boolean group_check) { this.group_check = group_check; } public String getSellerName() { return sellerName; } public void setSellerName(String sellerName) { this.sellerName = sellerName; } public String getSellerid() { return sellerid; } public void setSellerid(String sellerid) { this.sellerid = sellerid; } public List<ListBean> getList() { return list; } public void setList(List<ListBean> list) { this.list = list; } public static class ListBean { private double bargainPrice; private String createtime; private String detailUrl; private String images; private int num; private int pid; private double price; private int pscid; private int selected; private int sellerid; private String subhead; private String title; public double getBargainPrice() { return bargainPrice; } public void setBargainPrice(double bargainPrice) { this.bargainPrice = bargainPrice; } public String getCreatetime() { return createtime; } public void setCreatetime(String createtime) { this.createtime = createtime; } public String getDetailUrl() { return detailUrl; } public void setDetailUrl(String detailUrl) { this.detailUrl = detailUrl; } public String getImages() { return images; } public void setImages(String images) { this.images = images; } public int getNum() { return num; } public void setNum(int num) { this.num = num; } public int getPid() { return pid; } public void setPid(int pid) { this.pid = pid; } public double getPrice() { return price; } public void setPrice(double price) { this.price = price; } public int getPscid() { return pscid; } public void setPscid(int pscid) { this.pscid = pscid; } public int getSelected() { return selected; } public void setSelected(int selected) { this.selected = selected; } public int getSellerid() { return sellerid; } public void setSellerid(int sellerid) { this.sellerid = sellerid; } public String getSubhead() { return subhead; } public void setSubhead(String subhead) { this.subhead = subhead; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } } } }
//结算bean类
package com.example.jingdong.bean; /** * Created by huoxuebin on 2018/4/23. */ public class CountPriceBean { private String priceString; private int count; public CountPriceBean(String priceString, int count) { this.priceString = priceString; this.count = count; } public String getPriceString() { return priceString; } public void setPriceString(String priceString) { this.priceString = priceString; } public int getCount() { return count; } public void setCount(int count) { this.count = count; } }
//适配器代码
package com.example.jingdong.adapter; import android.content.Context; import android.os.Handler; import android.os.Message; import android.view.View; import android.view.ViewGroup; import android.widget.BaseExpandableListAdapter; import android.widget.CheckBox; import android.widget.ImageView; import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.Toast; import com.bumptech.glide.Glide; import com.example.jingdong.R; import com.example.jingdong.bean.CountPriceBean; import com.example.jingdong.bean.ShopBean; import com.example.jingdong.jiekou.OnItemClickListener; import com.example.jingdong.presenter.ShopPresenter; import com.example.jingdong.utils.BaseObserver; import com.example.jingdong.utils.RetrofitManager; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * Created by huoxuebin on 2018/4/25. */ public class ShopAdapter extends BaseExpandableListAdapter { private ShopPresenter presenter; private int uid=10190; private int childIndex; private int allIndex; private Context context; private ShopBean shopBean; private Handler handler; private RelativeLayout relative_progress; private OnItemClickListener onItemClickListener; public ShopAdapter(Context context, ShopBean shopBean, Handler handler, RelativeLayout relative_progress, ShopPresenter presenter) { this.context = context; this.shopBean = shopBean; this.handler = handler; this.relative_progress = relative_progress; this.presenter = presenter; } @Override public int getGroupCount() { return shopBean.getData().size(); } @Override public int getChildrenCount(int groupPosition) { return shopBean.getData().get(groupPosition).getList().size(); } @Override public Object getGroup(int groupPosition) { return shopBean.getData().get(groupPosition); } @Override public Object getChild(int groupPosition, int childPosition) { return shopBean.getData().get(groupPosition).getList().get(childPosition); } @Override public long getGroupId(int groupPosition) { return groupPosition; } @Override public long getChildId(int groupPosition, int childPosition) { return childPosition; } @Override public boolean hasStableIds() { return true; } @Override public View getGroupView(int groupPosition, boolean b, View view, ViewGroup viewGroup) { final GroupHolder holder; if (view == null){ view = View.inflate(context, R.layout.yijiliebiao,null); holder =