首页>代码>生鲜o2o配送开源系统,包括Android源码+SSH后台管理系统>/生鲜O2O源码/android端/freshO2O/app/src/main/java/com/freshO2O/adapter/CatergoryAdapter.java
package com.freshO2O.adapter; import java.util.ArrayList; import java.util.HashMap; import com.freshO2O.R; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.TextView; public class CatergoryAdapter extends BaseAdapter { private ArrayList<HashMap<String, Object>> data; /** * LayoutInflater 类是代码实现中获取布局文件的主要形式 *LayoutInflater layoutInflater = LayoutInflater.from(context); *View convertView = layoutInflater.inflate(); *LayoutInflater的使用,在实际开发种LayoutInflater这个类还是非常有用的,它的作用类似于 findViewById(), 不同点是LayoutInflater是用来找layout下xml布局文件,并且实例化! 而findViewById()是找具体xml下的具体 widget控件(如:Button,TextView等)。 */ private LayoutInflater layoutInflater; private Context context; public CatergoryAdapter(Context context) { this.context = context; this.layoutInflater = LayoutInflater.from(context); } public CatergoryAdapter(Context context,ArrayList<HashMap<String, Object>> data) { this.context = context; this.data = data; this.layoutInflater = LayoutInflater.from(context); } @Override public int getCount() { // TODO Auto-generated method stub return data.size(); } @Override public Object getItem(int position) { // TODO Auto-generated method stub return data.get(position); } @Override public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder=new ViewHolder(); //组装数据 if(convertView!=null){ convertView=layoutInflater.inflate(R.layout.activity_category_item, null); holder.image=(ImageView) convertView.findViewById(R.id.catergory_image); holder.title=(TextView) convertView.findViewById(R.id.catergoryitem_title); holder.content=(TextView) convertView.findViewById(R.id.catergoryitem_content); //使用tag存储数据 convertView.setTag(holder); }else{ holder=(ViewHolder) convertView.getTag(); } holder.image.setImageResource(mImageIds[position]); holder.title.setText(mTitleValues[position]); holder.content.setText(mContentValues[position]); return convertView; } // 适配显示的图片数组 private Integer[] mImageIds = {R.drawable.catergory_appliance,R.drawable.catergory_book,R.drawable.catergory_cloth,R.drawable.catergory_deskbook, R.drawable.catergory_digtcamer,R.drawable.catergory_furnitrue,R.drawable.catergory_mobile,R.drawable.catergory_skincare }; //给照片添加文字显示(Title) private String[] mTitleValues = { "家电", "图书", "衣服", "笔记本", "数码", "家具", "手机", "护肤" }; private String[] mContentValues={"家电/生活电器/厨房电器", "电子书/图书/小说","男装/女装/童装", "笔记本/笔记本配件/产品外设", "摄影摄像/数码配件", "家具/灯具/生活用品", "手机通讯/运营商/手机配件", "面部护理/口腔护理/..."}; public static class ViewHolder { ImageView image; TextView title; TextView content; } }
最近下载更多
ewan007 LV29
3月19日
晴曛 LV6
2023年12月29日
xiaoluo_123 LV3
2023年6月4日
2775645521 LV4
2023年5月24日
龙门客栈 LV9
2023年3月31日
Sunyibo LV1
2023年2月10日
东方之珠_1628 LV6
2023年1月7日
zhaoyangwfd LV17
2022年10月8日
微信网友_6094303684497408 LV4
2022年8月30日
ruishent LV6
2022年7月25日
最近浏览更多
wyyz5211314 LV4
4月7日
vluobo LV1
3月19日
ewan007 LV29
3月19日
WBelong LV7
3月8日
1134116035
2月21日
暂无贡献等级
yanixh LV1
2月19日
Gin19960217 LV4
1月15日
shachuan LV1
2023年12月29日
晴曛 LV6
2023年12月29日
微信网友_6786771336368128
2023年12月20日
暂无贡献等级