简单版购物车 是用二级列表 框架是MVP 请求网络的方法是OKHttp
以下是效果图
展开后的效果
部分中加减的功能是用自定义view实现的
GitHub地址 https://github.com/zzzzzjson/GoodsListDemo
以下上主要代码
布局文件 MVP框架不在展示
需要的依赖
implementation 'com.github.bumptech.glide:glide:4.8.0'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.squareup.okhttp3:okhttp:3.12.0'
适配器
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import java.util.ArrayList;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.concurrent.ForkJoinPool;
import soexample.umeng.com.androidgoodslist.MyView;
import soexample.umeng.com.androidgoodslist.R;
import soexample.umeng.com.androidgoodslist.bean.MyBean;
public class MyAdapter extends BaseExpandableListAdapter {
private ArrayList<MyBean.DataBean> list;
private Context context;
public MyAdapter(ArrayList<MyBean.DataBean> list, Context context) {
this.list = list;
this.context = context;
}
@Override
public int getGroupCount() {
return list.size();
}
@Override
public int getChildrenCount(int groupPosition) {
return list.get(groupPosition).getSpus().size();
}
@Override
public Object getGroup(int groupPosition) {
return null;
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return null;
}
@Override
public long getGroupId(int groupPosition) {
return 0;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return 0;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public View getGroupView(final int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
groupViewHolder viewHolder = null;
if (convertView == null) {
convertView = View.inflate(context, R.layout.group_view, null);
viewHolder = new groupViewHolder();
viewHolder.Group_ck = convertView.findViewById(R.id.Group_ck);
viewHolder.Group_title = convertView.findViewById(R.id.Group_title);
convertView.setTag(viewHolder);
} else {
viewHolder = (groupViewHolder) convertView.getTag();
}
viewHolder.Group_title.setText(list.get(groupPosition).getName());
boolean childAllCheck = isChildAllCheck(groupPosition);
viewHolder.Group_ck.setChecked(childAllCheck);
viewHolder.Group_ck.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (adapterCa