ListView通用适配器
来源:互联网 发布:血腥爱情故事 知乎 编辑:程序博客网 时间:2024/05/10 11:59
ListView通用适配器
package org.adapter;import java.lang.reflect.Field;import java.util.List;import java.util.Map;import java.util.Vector;import org.cache.TransformUtils;import android.content.Context;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.BaseAdapter;import android.widget.TextView;public class ListViewAdapater extends BaseAdapter {protected List<?> data;protected int[] ids;protected Context context;protected LayoutInflater inflater;List<View> cacheViews = null;public ListViewAdapater(List<?> data, int resource, int[] ids, String[] keys,Context context) {this.data = data;this.ids = ids;this.context = context;inflater = LayoutInflater.from(this.context);cacheViews = new Vector<View>();int count = getCount();for (int position = 0; position < count; position++) {View view = inflater.inflate(resource, null);for (int x = 0; x < ids.length; x++) {int id = ids[x];View tempView = view.findViewById(id);if (tempView instanceof TextView) {TextView tv = (TextView) tempView;tv.setText(TransformUtils.toString(getValue(position,keys[x])));}}}}@Overridepublic int getCount() {if (null == data) {return 0;}return data.size();}@Overridepublic Object getItem(int position) {return data.get(position);}@Overridepublic long getItemId(int position) {return position;}@Overridepublic View getView(int position, View convertView, ViewGroup parent) {return cacheViews.get(position);}public Object getValue(int position, String key) {Object obj = getItem(position);if (obj instanceof Map<?, ?>) {Map<?, ?> map = (Map<?, ?>) obj;return map.get(key);} else {try {Field field = obj.getClass().getDeclaredField(key);field.setAccessible(true);return field.get(obj);} catch (Exception e) {e.printStackTrace();}}return null;}}
0 0
- ListView通用适配器
- Android Listview通用适配器
- listview、gridview通用适配器
- ListView通用适配器
- ListView、GrideView通用适配器
- ListView 通用适配器
- listview通用适配器和RecyclerView通用适配器
- 【Android笔记】 通用ListView适配器
- 通用的ListView GridView适配器
- Android 通用ListView、GridView适配器
- Android Listview通用适配器BaseCommAdapter
- Android ListView的通用适配器Adapter
- Android 开发技巧-Listview通用适配器BaseCommAdapter
- 编写通用的Listview、gridview的适配器
- 23—自定义ListView【通用】适配器并实现监听控件
- 自定义ListView【通用】适配器并实现监听控件!
- 自定义ListView【通用】适配器并实现监听控件!
- Android 快速开发系列 万能通用的ListView GridView 适配器
- ASP.NET 如何获取地址栏URL地址
- 如何成为一名优秀的CTO
- 树莓派最新sudo rasp-config 系统设置 时间 全屏设置
- 如何通过Tesseract开源OCR引擎创建Android OCR应用
- VB中求Val("&H ffff")的返回值
- ListView通用适配器
- 计算公式
- EaseType效果直观展示
- 关于for循环的细节问题
- java初始化机制(二)
- Tor 1
- maven 添加本地jar
- Windows 关闭_IPV6_通道
- SVD在推荐系统中的应用