Android 二级列表

package com.bawei.zhaojianfu2019826r.view.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.TextView;

import com.bawei.zhaojianfu2019826r.R;
import com.bawei.zhaojianfu2019826r.model.bean.BeanGouWuChe;

import java.util.List;

//仅限于自己看
public class RecyAdapter extends RecyclerView.Adapter {
private List orderData;
private Context context;

public RecyAdapter(List orderData, Context context) {
    this.orderData = orderData;
    this.context = context;
}

@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
    View view = LayoutInflater.from(context).inflate(R.layout.item1,null);
    ViewHoder viewHoder = new ViewHoder(view);
    return viewHoder;
}

@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
    ViewHoder viewHoder = new ViewHoder(viewHolder.itemView);
    viewHoder.item1_shopName.setText(orderData.get(i).getShopName());

    viewHoder.item1_box.setChecked(orderData.get(i).isFucheng());

    //布局管理器
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
    linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    viewHoder.item1_recy.setLayoutManager(linearLayoutManager);


    //绑定适配器
    RecyAdapter2 recyAdapter2 = new RecyAdapter2(orderData.get(i).getCartlist(),context);
    viewHoder.item1_recy.setAdapter(recyAdapter2);

}

@Override
public int getItemCount() {
    return orderData.size();
}
class ViewHoder extends RecyclerView.ViewHolder {

    private final TextView item1_shopName;
    private final CheckBox item1_box;
    private final RecyclerView item1_recy;

    public ViewHoder(@NonNull View itemView) {
        super(itemView);
        item1_shopName = itemView.findViewById(R.id.item1_shopName);
        item1_box = itemView.findViewById(R.id.item1_box);
        item1_recy = itemView.findViewById(R.id.item1_recy);
    }
}

}

package com.bawei.zhaojianfu2019826r.view.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
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.ImageView;
import android.widget.TextView;

import com.bawei.zhaojianfu2019826r.R;
import com.bawei.zhaojianfu2019826r.model.bean.BeanGouWuChe;
import com.bumptech.glide.Glide;

import java.util.List;

public class RecyAdapter2 extends RecyclerView.Adapter {

private List orderData;
private Context context;

public RecyAdapter2(List orderData, Context context) {
    this.orderData = orderData;
    this.context = context;
}

@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
    View view = LayoutInflater.from(context).inflate(R.layout.item2,null);
    ViewHoder viewHoder =new ViewHoder(view);
    return viewHoder;
}

@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
    ViewHoder viewHoder = new ViewHoder(viewHolder.itemView);
    viewHoder.item2_price.setText(orderData.get(i).getPrice()+"");
    viewHoder.item2_productName.setText(orderData.get(i).getProductName());
    viewHoder.item2_box.setChecked(orderData.get(i).isZicheng());
    Glide.with(context)
            .load(orderData.get(i).getDefaultPic())
            .into(viewHoder.item2_defaultPic);
}

@Override
public int getItemCount() {
    return orderData.size();
}
class ViewHoder extends RecyclerView.ViewHolder {

    private final ImageView item2_defaultPic;
    private final TextView item2_productName;
    private final TextView item2_price;
    private final CheckBox item2_box;

    public ViewHoder(@NonNull View itemView) {


        super(itemView);
        item2_defaultPic = itemView.findViewById(R.id.item2_defaultPic);
        item2_productName = itemView.findViewById(R.id.item2_productName);
        item2_price = itemView.findViewById(R.id.item2_price);
        item2_box = itemView.findViewById(R.id.item2_box);
    }
}

}

你可能感兴趣的:(Android 二级列表)