其他分享
首页 > 其他分享> > 上下拉刷新,二级联动适配器

上下拉刷新,二级联动适配器

作者:互联网

ShowAdapter:
public class ShowAdapter extends XRecyclerView.Adapter<ShowAdapter.holder> {

    public Person person;
    public Context context;

    public ShowAdapter(Person person, Context context) {
        this.person = person;
        this.context = context;
    }

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

    @Override
    public void onBindViewHolder(@NonNull holder holder,final int i) {

        Person.DataBean dataBean=person.getData().get(i);
        RequestOptions options=RequestOptions.circleCropTransform();
        Glide.with(context).load(dataBean.getThumbnail_pic_s()).apply(options).into(holder.imageView);
        holder.text_name.setText(dataBean.getTitle());
        holder.text_price.setText(dataBean.getDate());
    }

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

    public class holder extends XRecyclerView.ViewHolder{

        public ImageView imageView;
        public TextView text_name,text_price;

        public holder(@NonNull View itemView) {
            super(itemView);

            imageView=itemView.findViewById(R.id.imageview);
            text_name=itemView.findViewById(R.id.text_name);
            text_price=itemView.findViewById(R.id.text_price);
        }
    }

}

LeftAdapter:
public class LeftAdapter extends RecyclerView.Adapter<LeftAdapter.holder> {

    public Left left;
    public Context context;

    public LeftAdapter(Left left, Context context) {
        this.left = left;
        this.context = context;
    }

    @NonNull
    @Override
    public holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.left, parent, false);
        return new holder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull holder holder, final int i) {
        Left.Result result = left.getResult().get(i);
        holder.textView.setText(result.getName());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                leftClick.leftonclick(i);
            }
        });
    }


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

    public class holder extends RecyclerView.ViewHolder {

        private TextView textView;
        public holder(View itemView) {
            super(itemView);
            textView = itemView.findViewById(R.id.left_text);
        }
    }
    LeftClick leftClick;
    public void leftclick(LeftClick leftClick){
        this.leftClick = leftClick;
    }
    public interface LeftClick{
        void leftonclick(int position);
    }
}

MiddleAdapter:
public class MiddleAdapter extends RecyclerView.Adapter<MiddleAdapter.holder> {

    public Middle middle;
    public Context context;

    public MiddleAdapter(Middle middle, Context context) {
        this.middle = middle;
        this.context = context;
    }

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

    @Override
    public void onBindViewHolder(@NonNull holder holder,final int i) {

        Middle.Result result=middle.getResult().get(i);

        holder.middle_name.setText(result.getName());

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                middleClick.middleonclick(i);
            }
        });
    }

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

    public class holder extends RecyclerView.ViewHolder{

        public TextView middle_name;

        public holder(@NonNull View itemView) {
            super(itemView);

            middle_name=itemView.findViewById(R.id.middle_text);
        }
    }
    MiddleAdapter.MiddleClick middleClick;

    public void middleclick(MiddleAdapter.MiddleClick middleClick) {
        this.middleClick = middleClick;
    }
    public interface MiddleClick{
        public void middleonclick(int position);
    }
}
RightAdapter:
public class RightAdapter extends RecyclerView.Adapter<RightAdapter.holder> {

    public Right right;
    public Context context;

    public RightAdapter(Right right, Context context) {
        this.right = right;
        this.context = context;
    }

    @NonNull
    @Override
    public holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.right, parent, false);
        return new holder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull holder holder,final int i) {

        Right.Result result=right.getResult().get(i);
        RequestOptions options=RequestOptions.circleCropTransform();
        Glide.with(context).load(result.getMasterPic()).error(R.drawable.ic_launcher_background).apply(options).into(holder.imageView);
        holder.textView1.setText(result.getCommodityName());
        holder.textView2.setText(result.getPrice());
    }


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

    public class holder extends RecyclerView.ViewHolder {

        private TextView textView1,textView2;
        private ImageView imageView;
        public holder(View itemView) {
            super(itemView);
            textView1 = itemView.findViewById(R.id.text1);
            textView2 = itemView.findViewById(R.id.text2);
            imageView = itemView.findViewById(R.id.image);
        }
    }
}

 

标签:联动,itemView,int,适配器,context,刷新,Override,holder,public
来源: https://blog.csdn.net/weixin_43584998/article/details/89813550