自定义ArrayAdapter 自定义格式
private static class EfficientAdapter extends BaseAdapter {
private LayoutInflater mInflater;
private Bitmap mIcon1;
private Bitmap mIcon2;
public EfficientAdapter(Context context) {
// Cache the LayoutInflate to avoid asking for a new one each time.
mInflater = LayoutInflater.from(context);
// Icons bound to the rows.
mIcon1 = BitmapFactory.decodeResource(context.getResources(), R.drawable.icon48x48_1);
mIcon2 = BitmapFactory.decodeResource(context.getResources(), R.drawable.icon48x48_2);
}
/**
* The number of items in the list is determined by the number of speeches
* in our array.
*
* @see android.widget.ListAdapter#getCount()
*/
public int getCount() {
return DATA.length;
}
/**
* Since the data comes from an array, just returning the index is
* sufficent to get at the data. If we were using a more complex data
* structure, we would return whatever object represents one row in the
* list.
*
* @see android.widget.ListAdapter#getItem(int)
*/
public Object getItem(int position) {
return position;
}
/**
* Use the array index as a unique id.
*
* @see android.widget.ListAdapter#getItemId(int)
*/
public long getItemId(int position) {
return position;
}
/**
* Make a view to hold each row.
*
* @see android.widget.ListAdapter#getView(int, android.view.View,
* android.view.ViewGroup)
*/
public View getView(int position, View convertView, ViewGroup parent) {
// A ViewHolder keeps references to children views to avoid unneccessary calls
// to findViewById() on each row.
ViewHolder holder;
// When convertView is not null, we can reuse it directly, there is no need
// to reinflate it. We only inflate a new View when the convertView supplied
// by ListView is null.
if (convertView == null) {
convertView = mInflater.inflate(R.layout.list_item_icon_text, null);
// Creates a ViewHolder and store references to the two children views
// we want to bind data to.
holder = new ViewHolder();
holder.text = (TextView) convertView.findViewById(R.id.text);
holder.icon = (ImageView) convertView.findViewById(R.id.icon);
convertView.setTag(holder);
} else {
// Get the ViewHolder back to get fast access to the TextView
// and the ImageView.
holder = (ViewHolder) convertView.getTag();
}
// Bind the data efficiently with the holder.
holder.text.setText(DATA[position]);
holder.icon.setImageBitmap((position & 1) == 1 ? mIcon1 : mIcon2);
return convertView;
}
static class ViewHolder {
TextView text;
ImageView icon;
}
}
EG
分享到:
相关推荐
android ApiDemo android ApiDemo
android apidemo.apk
把Android Apidemo第一个例子抽出来,以后每学一节就加进Apidemo框架里,加深理解
学习android 的sample apidemo 以后要用到这些例子 方便自己方便别人
Google官方API(Android ApiDemo) 打包下载,初学者学习的捷径
android sdk中拿出来的 android api demo,sdk\samples\android-17,给需要的人
关于apidemo的例子,里面的例子非常的不错啊
Android官方apidemo,android studio直接导入,运行安装即可
android apidemo android apidemo android apidemo
谷歌官方Android ApiDemo,可直接导入Android Studio,全部配置好,导入即可跑通安装!
android 示例源码 apidemo 内容很全的,直接导入即可使用学习
android中文apidemo详解事例,适合新手阅读快速上手。
android APIdemo 深入分析
Android的Apidemo 的代码分析。非常好的资料,欢迎大家下载学习
腾讯微博APIDemo aip sdk
最新6.0,最新APIDEMO
在SpringBoot中应用swagger2的一个DEMO,主要功能包括:WEB访问API,API导出为adoc、html、pdf。项目中有中文字体文件,使用的时候先删除目录docs、html和pdf目录,启动项目,然后点击...可方便的移植到自己的项目中。
百度地图API使用,及Demo。一套应用程序接口,帮助开发者构建功能丰富、交互性强的地图应用程序。 JavaScript API Mobile API Web Services Flash API 导航控件 缩略图控件 地图类型控件 比例尺控件 ...