一级列表适配器

package com.example.aason.gouwuche1.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;

import com.example.aason.gouwuche1.R;
import com.example.aason.gouwuche1.bean.CartBean;
import com.jcodecraeer.xrecyclerview.XRecyclerView;

import java.util.ArrayList;
import java.util.List;

public class UserAdapter extends XRecyclerView.Adapter {
private Context context;
private List cart;
private ProdAdapter prodAdapter;
private int a;

public UserAdapter(Context context, List cart) {
    this.context = context;
    this.cart = cart;
}

@NonNull
@Override
public MyVh onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
    View view = LayoutInflater.from(context).inflate(R.layout.item,viewGroup,false);
    return new MyVh(view);
}

@Override
public void onBindViewHolder(@NonNull MyVh myVh, int i) {
    a=i;
    CartBean.DataBean dataBean = cart.get(i);
    myVh.name.setText(dataBean.getName());
    myVh.ckk.setChecked(dataBean.isChecked);
    prodAdapter = new ProdAdapter(context,cart,i);
    myVh.rv.setLayoutManager(new LinearLayoutManager(context));
    myVh.rv.setAdapter(prodAdapter);

}

@Override
public int getItemCount() {
    return cart.size();
}

public class MyVh extends RecyclerView.ViewHolder {

    private final CheckBox ckk;
    private final TextView name;
    private final XRecyclerView rv;

    public MyVh(@NonNull View itemView) {
        super(itemView);
        ckk = itemView.findViewById(R.id.ckk);
        name = itemView.findViewById(R.id.name);
        rv = itemView.findViewById(R.id.rv);
    }
}

}

你可能感兴趣的:(一级列表适配器)