大的Adapter

package com.bawai.dianshang.adapter;

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.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bawai.dianshang.R;
import com.bawai.dianshang.bean.BannerBean;
import com.bawai.dianshang.bean.ShouBean;
import com.bumptech.glide.Glide;
import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.stx.xhb.xbanner.XBanner;

import java.util.List;

/**

  • @Author:不要不要

  • @E-mail: 2930851278@qq.com

  • @Date:2019/3/30 14:43

  • @Description:描述信息
    */
    public class ShowAdapter extends XRecyclerView.Adapter<RecyclerView.ViewHolder> {
    Context context;
    ShouBean shouBean;
    BannerBean bannerBean;
    private final int Banner_TYPE = 0;
    private final int RXXP_TYPE=1;
    private final int PZSH_TYPE=3;
    private final int MLSS_TYPE=2;
    private XBannerHolder xBannerHolder;
    private RxxpHolder rxxpHolder;
    private LinearLayoutManager linearLayoutManager;
    private List<ShouBean.ResultBean.RxxpBean.CommodityListBean> commodityList;
    private List<BannerBean.ResultBean> result;
    private LinearLayoutManager linearLayoutManager1;
    private List<ShouBean.ResultBean.MlssBean.CommodityListBeanXX> commodityList1;
    private LinearLayoutManager linearLayoutManager2;
    private List<ShouBean.ResultBean.PzshBean.CommodityListBeanX> commodityList2;
    private RxxpAdapter rxxpAdapter;

    public ShowAdapter(Context context, ShouBean shouBean, BannerBean bannerBean) {
    this.context = context;
    this.shouBean = shouBean;
    this.bannerBean = bannerBean;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
    View view;
    if (iBanner_TYPE){
    view= LayoutInflater.from(context).inflate(R.layout.banner_items,viewGroup,false);
    xBannerHolder = new XBannerHolder(view);
    return xBannerHolder;
    }else if(i
    RXXP_TYPE){
    view= LayoutInflater.from(context).inflate(R.layout.one_items,viewGroup,false);
    rxxpHolder = new RxxpHolder(view);
    return rxxpHolder;
    }else if(iMLSS_TYPE){
    view= LayoutInflater.from(context).inflate(R.layout.two_items,viewGroup,false);
    MlssHolder mlssHolder=new MlssHolder(view);
    return mlssHolder;
    }else if(i
    PZSH_TYPE){
    view= LayoutInflater.from(context).inflate(R.layout.three_items,viewGroup,false);
    PzshHolder pzshHolder=new PzshHolder(view);
    return pzshHolder;
    }
    return null;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, final int i) {
    if (viewHolder instanceof XBannerHolder){
    XBannerHolder xBannerHolder= (XBannerHolder) viewHolder;
    result = bannerBean.getResult();
    xBannerHolder.xbanner1.setData(result,null);
    xBannerHolder.xbanner1.setmAdapter(new XBanner.XBannerAdapter() {
    @Override
    public void loadBanner(XBanner banner, View view, int position) {
    Glide.with(context).load(result.get(position).getImageUrl()).into((ImageView) view);
    }
    });

         }else if (viewHolder instanceof RxxpHolder){
         RxxpHolder rxxpHolder= (RxxpHolder) viewHolder;
         rxxpHolder.text1111.setText(shouBean.getResult().getRxxp().getName());
             linearLayoutManager = new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false);
             rxxpHolder.rec1.setLayoutManager(linearLayoutManager);
             commodityList = shouBean.getResult().getRxxp().getCommodityList();
             rxxpAdapter = new RxxpAdapter(context, commodityList);
             rxxpHolder.rec1.setAdapter(rxxpAdapter);
             rxxpAdapter.setDatas(new RxxpAdapter.BBCallback() {
                 @Override
                 public void ondate(int id, Object data) {
                     Toast.makeText(context,"id="+data,Toast.LENGTH_SHORT).show();
                 }
             });
    
         }else if (viewHolder instanceof MlssHolder){
         MlssHolder mlssHolder= (MlssHolder) viewHolder;
         mlssHolder.text2222.setText(shouBean.getResult().getMlss().getName());
             linearLayoutManager1 = new LinearLayoutManager(context);
             mlssHolder.rec2.setLayoutManager(linearLayoutManager1);
             commodityList1 = shouBean.getResult().getMlss().getCommodityList();
             mlssHolder.rec2.setAdapter(new MlssAdapter(context,commodityList1));
         }else if (viewHolder instanceof PzshHolder){
             PzshHolder pzshHolder= (PzshHolder) viewHolder;
             pzshHolder.text3333.setText(shouBean.getResult().getPzsh().getName());
    
             linearLayoutManager2 = new GridLayoutManager(context,2);
             pzshHolder.rec3.setLayoutManager(linearLayoutManager2);
             commodityList2 = shouBean.getResult().getPzsh().getCommodityList();
             pzshHolder.rec3.setAdapter(new PzshAdapter(context,commodityList2));
    
         }
    

    }

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

    @Override
    public int getItemViewType(int position) {
    if (position0){
    return Banner_TYPE;
    }else if (position
    1){
    return RXXP_TYPE;
    }else if (position2){
    return MLSS_TYPE;
    }else if (position
    3){
    return PZSH_TYPE;
    }

     return super.getItemViewType(position);
    

    }

    public class RxxpHolder extends RecyclerView.ViewHolder{
    private final TextView text1111;
    private final RecyclerView rec1;
    public RxxpHolder(@NonNull View itemView) {
    super(itemView);
    text1111 = itemView.findViewById(R.id.text1111);
    rec1 = itemView.findViewById(R.id.rec1);
    }
    }

    public class MlssHolder extends RecyclerView.ViewHolder{
    private final TextView text2222;
    private final RecyclerView rec2;
    public MlssHolder(@NonNull View itemView) {
    super(itemView);
    text2222 = itemView.findViewById(R.id.text2222);
    rec2 = itemView.findViewById(R.id.rec2);
    }
    }

    public class PzshHolder extends RecyclerView.ViewHolder{

     private final TextView text3333;
     private final RecyclerView rec3;
    
     public PzshHolder(@NonNull View itemView) {
         super(itemView);
         text3333 = itemView.findViewById(R.id.text3333);
         rec3 = itemView.findViewById(R.id.rec3);
     }
    

    }

    public class XBannerHolder extends RecyclerView.ViewHolder{

     private final XBanner xbanner1;
    
     public XBannerHolder(@NonNull View itemView) {
         super(itemView);
         xbanner1 = itemView.findViewById(R.id.xbanner1);
     }
    

    }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值