zoukankan      html  css  js  c++  java
  • 安卓适配器代码

    package com.example.administrator.ls.adapter;
    
    import android.content.Context;
    import android.support.v7.widget.RecyclerView;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.BaseAdapter;
    import android.widget.ImageView;
    import android.widget.TextView;
    
    import com.example.administrator.ls.ItemBean;
    import com.example.administrator.ls.R;
    
    import java.util.List;
    
    
    
    public class MyAdapter extends BaseAdapter {
        private List<ItemBean> mList;
        private LayoutInflater mInflater;
    
        public MyAdapter(Context context,List<ItemBean> list){
            mList=list;
            mInflater=LayoutInflater.from(context);
        }
    
        @Override
        public int getCount() {
            return mList.size();
        }
    
        @Override
        public Object getItem(int position) {
            return mList.get(position);
        }
    
        @Override
        public long getItemId(int position) {
            return position;
        }
    
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder viewHolder;
            if(convertView==null)
            {
                viewHolder=new ViewHolder();
                convertView=mInflater.inflate(R.layout.activity_item,null);
                viewHolder.imageView=(ImageView)convertView.findViewById(R.id.iv_image);
                viewHolder.title=(TextView)convertView.findViewById(R.id.tv_title);
                viewHolder.content=(TextView)convertView.findViewById(R.id.tv_content);
                convertView.setTag(viewHolder);
            }
            else{
                viewHolder = (ViewHolder)convertView.getTag();
            }
            ItemBean bean = mList.get(position);
    
            ItemBean itemBean = mList.get(position);
    
            viewHolder.imageView.setImageResource(itemBean.itemImageResId);
            viewHolder.title.setText(itemBean.itemTitle);
            viewHolder.content.setText(itemBean.itemContent);
    
            return convertView;
        }
    }
    class ViewHolder{
        public ImageView imageView;
        public TextView title;
        public TextView content;
    }
  • 相关阅读:
    单例模式(Singleton)的6种实现
    深入浅出单实例Singleton设计模式
    Singleton单例模式
    面试中的Singleton
    海量数据存储之Key-Value存储简介
    大数据时代的 9 大Key-Value存储数据库
    python 多线程两种实现方式,Python多线程下的_strptime问题,
    pycURL的内存问题
    百万级访问网站前期的技术准备
    IPv6 tutorial – Part 6: Site-local addresses and link-local addresses
  • 原文地址:https://www.cnblogs.com/norm/p/7989317.html
Copyright © 2011-2022 走看看