适配器

大的
package bawei.com.fjb.fengjiabaoyuekao.adapter;

import android.content.Context;
import android.icu.text.PluralRules;
import android.support.annotation.NonNull;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.youth.banner.Banner;
import com.youth.banner.loader.ImageLoader;

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

import bawei.com.fjb.fengjiabaoyuekao.R;
import bawei.com.fjb.fengjiabaoyuekao.entity.HomeEntity;
import butterknife.BindView;
import butterknife.ButterKnife;

public class MyHomeAdapter extends RecyclerView.Adapter {
    private Context context;
    private HomeEntity homeEntity;

    public MyHomeAdapter(Context context, HomeEntity homeEntity) {
        this.context = context;
        this.homeEntity = homeEntity;
    }

    @Override
    public int getItemViewType(int position) {
        if(position==0){
            return 0;
        }
        if(position==1){
            return 1;
        }
        if(position==2){
            return 2;
        }
        return super.getItemViewType(position);
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view;
        RecyclerView.ViewHolder holder=null;
        switch (viewType){
            case 0:
                view=View.inflate(context, R.layout.home_looper,null);
                holder=new BannerHolder(view);
                break;
            case 1:
                view=View.inflate(context, R.layout.home_sort,null);
                holder=new SortHolder(view);
                break;
            case 2:
                view=View.inflate(context, R.layout.home_miaosha,null);
                holder=new MiaoShaoHolder(view);
                break;
        }
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        if(holder instanceof BannerHolder){
            List<String> list=ListAdd(homeEntity.getData());
            ((BannerHolder) holder).banner.setImageLoader(new MyLoader())
                    .setImages(list)
                    .start();
        }else if(holder instanceof MiaoShaoHolder){
            ((MiaoShaoHolder) holder).home_miaosha_recycler.setLayoutManager(new GridLayoutManager(context,2));
            MyMiaoAdapter myMiaoAdapter = new MyMiaoAdapter(homeEntity.getMiaosha().getList(),context);
            ((MiaoShaoHolder) holder).home_miaosha_recycler.setAdapter(myMiaoAdapter);
        }
    }



    @Override
    public int getItemCount() {
        return 3;
    }
    private List<String> ListAdd(List<HomeEntity.DataBean> data) {
        List<String> img=new ArrayList<>();
        for (HomeEntity.DataBean imgs :data){
            img.add(imgs.getIcon());
        }
        return img;
    }

    static class BannerHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.banner)
        Banner banner;
        public BannerHolder(View view) {
            super(view);
            ButterKnife.bind(this,view);
        }
    }
    static class SortHolder extends RecyclerView.ViewHolder {

        public SortHolder(View view) {
            super(view);
        }
    }
    private class MyLoader extends ImageLoader{

        @Override
        public void displayImage(Context context, Object path, ImageView imageView) {
            Glide.with(context).load((String) path).into(imageView);
        }
    }

    static class MiaoShaoHolder  extends RecyclerView.ViewHolder{
        @BindView(R.id.home_miaosha_recycler)
        RecyclerView home_miaosha_recycler;
        public MiaoShaoHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }

}

 

 

 

晓得

package bawei.com.fjb.fengjiabaoyuekao.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;

import org.w3c.dom.Text;

import java.util.List;
import java.util.Random;

import bawei.com.fjb.fengjiabaoyuekao.R;
import bawei.com.fjb.fengjiabaoyuekao.entity.HomeEntity;
import butterknife.BindView;
import butterknife.ButterKnife;

public class MyMiaoAdapter extends RecyclerView.Adapter<MyMiaoAdapter.ViewHolder> {
    private List<HomeEntity.MiaoshaBean.ListBeanX> listBeanXES;
    private Context context;
    String[] strings = {"一加手机3","秒杀苹果8","小米新机","华为mate","魅族手机"};


    public MyMiaoAdapter(List<HomeEntity.MiaoshaBean.ListBeanX> listBeanXES, Context context) {
        this.listBeanXES = listBeanXES;
        this.context = context;
    }


    @NonNull
    @Override
    public MyMiaoAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view=View.inflate(context,R.layout.home_miao_item,null);
        ViewHolder holder=new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull MyMiaoAdapter.ViewHolder holder, int position) {

        try {
         Log .i("aaa",listBeanXES.get(position).getTitle());
         holder.home_miao_list_tv.setText(listBeanXES.get(position).getTitle());
         holder.home_miao_list_iv.setImageURI(listBeanXES.get(position).getImages().split("\\|")[position]);
        }catch (Exception e){

        }

    }

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

    public class ViewHolder extends RecyclerView.ViewHolder {
        SimpleDraweeView home_miao_list_iv;
        TextView home_miao_list_tv;
        public ViewHolder(View itemView) {
            super(itemView);
            home_miao_list_tv= itemView.findViewById(R.id.home_miao_list_tv);
            home_miao_list_iv=itemView.findViewById(R.id.home_miao_list_iv);
        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值