卧疾丰暇豫,翰墨时间作。这篇文章主要讲述安卓适配器代码相关的知识,希望能为你提供帮助。
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; }
【安卓适配器代码】
推荐阅读
- Android Studio 打包生成 APK
- Android浏览器访问java web的方法
- 解决Android 6.0获取wifi Mac地址为02:00:00:00:00:00问题
- 安卓项目回顾
- callapplybind的用法
- Dapper入门使用,代替你的DbSQLhelper
- msoffice系统工具图文详细教程处理蓝屏代码0x0000007b
- msoffice系统工具图文详细教程电脑硬盘坏了怎样办
- msoffice系统工具图文详细教程如何运用3g无线网卡