package com.example.mvptext.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.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.example.mvptext.R;
import com.example.mvptext.model.JsenBean;
import java.util.List;
/**
* @Auther: 白俊岭
* @Date: 2019/3/17 11:08:45
* @Description:
*/
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.Viewholder> {
Context context;
List<JsenBean.DataBeanX.DataBean> jsenBean;
List<String> pics;
public MyAdapter(Context context, List<JsenBean.DataBeanX.DataBean> jsenBean, List<String> pics) {
this.context = context;
this.jsenBean = jsenBean;
this.pics=pics;
}
@Override
public int getItemViewType(int position) {
return position%2;
}
@NonNull
@Override
public Viewholder onCreateViewHolder(@NonNull ViewGroup parent, int viewType)
{
View view = LayoutInflater.from(context).inflate(R.layout.item, parent, false);
Viewholder viewholder = new Viewholder(view);
return viewholder;
}
@Override
public void onBindViewHolder(@NonNull Viewholder holder, int position)
{
int type = getItemViewType(position);
switch (type)
{
case 0:
holder.name.setText(jsenBean.get(position).getTitle());
Glide.with(context)
.load(pics.get(0))
.into(holder.img);
break;
case 1:
holder.name1.setText(jsenBean.get(position).getTitle());
Glide.with(context)
.load(jsenBean.get(position).getPic_amount())
.into(holder.img1);
break;
}
}
@Override
public int getItemCount() {
return jsenBean.size();
}
public class Viewholder extends RecyclerView.ViewHolder {
ImageView img;
TextView name;
ImageView img1;
TextView name1;
public Viewholder(View itemView) {
super(itemView);
img = itemView.findViewById(R.id.img);
name = itemView.findViewById(R.id.name);
img1 = itemView.findViewById(R.id.img1);
name1 = itemView.findViewById(R.id.name1);
}
}
}
多条目
最新推荐文章于 2019-06-02 20:17:48 发布