RecyAdapter包含三个recycle的适配器

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

import com.bawei.dianshang.R;
import com.bawei.dianshang.ShouActivity;
import com.bawei.dianshang.bean.HomeBean;

import java.util.List;

/**

  • @Author:苏羡c

  • @E-mail:

  • @Date:2019/3/26 19:32

  • @Description:描述信息
    */
    public class RecyAdapter extends RecyclerView.Adapter {

    Context context;
    HomeBean homeBean;
    private int RXXP_TYPE =0;
    private int MLSS_TYPE =1;
    private int PZSH_TYPE =2;
    private View view;
    private List commodityList;
    private List commodityList1;
    private List commodityList2;

    public RecyAdapter(Context context, HomeBean homeBean) {
    this.context = context;
    this.homeBean = homeBean;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
    if (iRXXP_TYPE){
    view = LayoutInflater.from(context).inflate(R.layout.rxxp_item, viewGroup, false);
    RxxpHoldle rxxpHoldle = new RxxpHoldle(view);
    return rxxpHoldle;
    }else if (i
    MLSS_TYPE){
    view = LayoutInflater.from(context).inflate(R.layout.mlss_item,viewGroup,false);
    MLSSHoldle mlssHoldle = new MLSSHoldle(view);
    return mlssHoldle;
    }else if (i==PZSH_TYPE){
    view = LayoutInflater.from(context).inflate(R.layout.pzsh_item,viewGroup,false);
    PZSHHoldle pzshHoldle = new PZSHHoldle(view);
    return pzshHoldle;
    }
    return null;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
    if (viewHolder instanceof RxxpHoldle){
    RxxpHoldle rxxpHoldle = (RxxpHoldle) viewHolder;
    //热销新品
    rxxpHoldle.rexiao_text.setText(homeBean.getResult().getRxxp().getName());
    //布局管理器
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context,LinearLayoutManager.HORIZONTAL,false);
    rxxpHoldle.rexiao_view.setLayoutManager(linearLayoutManager);
    commodityList = homeBean.getResult().getRxxp().getCommodityList();
    OneAdapter oneAdapter = new OneAdapter(context, commodityList);
    rxxpHoldle.rexiao_view.setAdapter(oneAdapter);
    }else if (viewHolder instanceof MLSSHoldle){
    MLSSHoldle mlssHoldle = (MLSSHoldle) viewHolder;
    //魔力时尚
    mlssHoldle.moli_text.setText(homeBean.getResult().getMlss().getName());
    //布局管理器
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context,LinearLayoutManager.VERTICAL,false);
    mlssHoldle.moli_view.setLayoutManager(linearLayoutManager);
    commodityList2 = homeBean.getResult().getMlss().getCommodityList();
    TwoAdapter twoAdapter = new TwoAdapter(context,commodityList2);
    mlssHoldle.moli_view.setAdapter(twoAdapter);
    }else if (viewHolder instanceof PZSHHoldle){
    PZSHHoldle pzshHoldle = (PZSHHoldle) viewHolder;
    //品质生活
    pzshHoldle.pinzhi_text.setText(homeBean.getResult().getPzsh().getName());
    //布局
    GridLayoutManager gridLayoutManager = new GridLayoutManager(context,2);
    pzshHoldle.pinzhi_view.setLayoutManager(gridLayoutManager);
    commodityList1 = homeBean.getResult().getPzsh().getCommodityList();
    ThreeAdapter threeAdapter = new ThreeAdapter(context,commodityList1);
    pzshHoldle.pinzhi_view.setAdapter(threeAdapter);
    }
    }

    @Override
    public int getItemCount() {
    return 2;
    }

    @Override
    public int getItemViewType(int position) {
    if(position0){
    return RXXP_TYPE;
    }else if (position
    1){
    return MLSS_TYPE;
    }else if (position==2){
    return PZSH_TYPE;
    }
    return super.getItemViewType(position);
    }

    //自定义holder
    public class RxxpHoldle extends RecyclerView.ViewHolder{
    private TextView rexiao_text;
    private final RecyclerView rexiao_view;

     public RxxpHoldle(@NonNull View itemView) {
         super(itemView);
         rexiao_text = itemView.findViewById(R.id.rexiao_text);
         rexiao_view = itemView.findViewById(R.id.rexiao_view);
     }
    

    }
    public class PZSHHoldle extends RecyclerView.ViewHolder{

     private final TextView pinzhi_text;
     private final RecyclerView pinzhi_view;
    
     public PZSHHoldle(@NonNull View itemView) {
         super(itemView);
         pinzhi_text = itemView.findViewById(R.id.pinzhi_text);
         pinzhi_view = itemView.findViewById(R.id.pinzhi_view);
     }
    

    }
    public class MLSSHoldle extends RecyclerView.ViewHolder{

     private final TextView moli_text;
     private final RecyclerView moli_view;
    
     public MLSSHoldle(@NonNull View itemView) {
         super(itemView);
         moli_text = itemView.findViewById(R.id.moli_text);
         moli_view = itemView.findViewById(R.id.moli_view);
     }
    

    }

}

你可能感兴趣的:(RecyAdapter包含三个recycle的适配器)