Adapter

作者: 红桃小花 | 来源:发表于2017-08-25 09:45 被阅读0次

    public classAdapte rextend sRecyclerView.Adapter<RecycleView.ViewHolder>{

    private List <Months.DataBean>list;

    privateContextcontext;

    inthead=1;

    intfoot=1;

    public static final intITEM_TYPE_HEADER=0;

    public static final intITEM_TYPE_CONTENT=1;

    public static final intITEM_TYPE_BOTTOM=2;

    public Adapter(List<Months.DataBean> list, Context context) {

    this.list= list;

    this.context= context;

    }

    @Override

    publicRecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent,intviewType) {

    View inflate = LayoutInflater.from(context).inflate(R.layout.madapter, parent,false);

    finalViewHolder viewholder =newViewHolder(inflate);

    ObjectAnimator.ofFloat(inflate,"alpha",0f,1f)

    .setDuration(5000).start();

    inflate.setOnClickListener(newView.OnClickListener() {

    @Override

    public voidonClick(View view) {

    }

    });

    viewholder.image.setOnClickListener(newView.OnClickListener() {

    @Override

    public voidonClick(View view) {

    intposition =viewholder.getAdapterPosition();

    String s =list.get(position).getTitle();

    Toast.makeText(context,"点击了第"+ position +"个图片,信息:"+s, Toast.LENGTH_SHORT).show();

    }

    });

    viewholder.tv.setOnClickListener(newView.OnClickListener() {

    @Override

    public voidonClick(View view) {

    intposition =viewholder.getAdapterPosition();

    Toast.makeText(context,"点击了第"+ position +"个图片下的文字条目", Toast.LENGTH_SHORT).show();

    }

    });

    returnviewholder;

    }

    @Override

    public voidonBindViewHolder(RecyclerView.ViewHolder holder,intposition) {

    ViewHolder hoders = (ViewHolder) holder;

    Glide.with(context).load(list.get(position).getUserImg()).into(hoders.image);

    hoders.tv.setText(list.get(position).getIntroduction() +"");

    hoders.age.setText(list.get(position).getUserAge()+"");

    hoders.work.setText(list.get(position).getOccupation()+"");

    }

    @Override

    public intgetItemCount() {

    returnlist==null?0:list.size();

    }

    static  class ViewHolder extends RecyclerView.ViewHolder{

    ImageViewimage;

    TextViewtv;

    TextViewage,work;

    publicViewHolder(View itemView) {

    super(itemView);

    image= itemView.findViewById(R.id.monimages);

    tv= itemView.findViewById(R.id.montv);

    age= itemView.findViewById(R.id.age);

    work= itemView.findViewById(R.id.work);

    }

    }

    }

    相关文章

      网友评论

          本文标题:Adapter

          本文链接:https://www.haomeiwen.com/subject/ukxudxtx.html