zoukankan      html  css  js  c++  java
  • 每日学习

    今天讲述团队项目第一阶段中对recyclerview的适配器配置,

    package com.example.bowenwang;
    
    import android.content.Context;
    import android.content.Intent;
    import android.os.Bundle;
    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 androidx.annotation.NonNull;
    import androidx.recyclerview.widget.RecyclerView;
    
    import com.bumptech.glide.Glide;
    
    import java.util.List;
    
    public class RecyclerAdapter2 extends RecyclerView.Adapter<RecyclerAdapter2.Hoder> {
        List<Bean> mlist;
        private Context mContext;
        public RecyclerAdapter2(List<Bean> mlist) {
            this.mlist = mlist;
        }
        @NonNull
        @Override
        public Hoder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            mContext=parent.getContext();
            LayoutInflater inflater = LayoutInflater.from(parent.getContext());
            View view=inflater.inflate(R.layout.list_item,parent,false);
            Hoder hoder=new Hoder(view);
            return hoder;
        }
    
        @Override
        public void onBindViewHolder(@NonNull Hoder holder, int position) {
            holder.title.setText(mlist.get(position).getTitle());
            holder.time.setText(mlist.get(position).getTime());
            holder.place.setText(mlist.get(position).getPlace());
            String img=mlist.get(position).getImg();
            if(img.equals("无")){
                Glide.with(mContext).load("http://n.sinaimg.cn/default/feedbackpics/transform/116/w550h366/20180326/gx3A-fysqfnf9556450.png").into(holder.img);
            }
            else {
                Glide.with(mContext).load(img.trim()).into(holder.img);
            }
            int p=position;
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Bean bean=new Bean();
                    bean.setTitle(mlist.get(p).getTitle());
                    bean.setTime(mlist.get(p).getTime());
                    bean.setPlace(mlist.get(p).getPlace());
                    bean.setContent(mlist.get(p).getContent());
                    Toast.makeText(mContext,bean.getTitle(),Toast.LENGTH_SHORT).show();
                    Intent iti=new Intent(mContext,DetailActivity.class);
                    Bundle bundle = new Bundle();
                    bundle.putSerializable("bean",bean);
                    iti.putExtras(bundle);
                    mContext.startActivity(iti);
                }
            });
        }
    
        @Override
        public int getItemCount() {
            return mlist.size();
        }
        class Hoder extends RecyclerView.ViewHolder{
             TextView title;
             TextView time;
             TextView place;
             ImageView img;
            public Hoder(@NonNull View itemView) {
                super(itemView);
                title=itemView.findViewById(R.id.tv_title);
                time=itemView.findViewById(R.id.tv_time);
                place=itemView.findViewById(R.id.tv_place);
                img=itemView.findViewById(R.id.iv_portrait);
            }
        }
    }
    

     这里是我的团队项目中的适配器,可以看到后需要配置一些什么。

    作者:哦心有
    本文版权归作者和博客园共有,欢迎转载,但必须给出原文链接,并保留此段声明,否则保留追究法律责任的权利。
  • 相关阅读:
    ecstore前台模板变量处理
    MySQL慢查询日志总结
    Linux 操作MySQL常用命令行
    CGI、FastCGI和php-fpm的概念和区别
    sync实现windows与nginx主机端文件同步(参考文档)
    PHP实现四种基本排序算法
    http和https协议
    linux的计划任务
    php封装一个接口类
    mysql的常见面试问题
  • 原文地址:https://www.cnblogs.com/haobox/p/14908945.html
Copyright © 2011-2022 走看看