您的位置:首页 > 移动开发 > Android开发

Android中的适配器

2015-10-31 13:23 337 查看
上网查了很多资料,决定整理些东西,也是对过去一个阶段的总结,里面有很多事网上查找的资料。

首先,Adapter是连接后端数据和前端显示的适配器接口,是数据和UI(View)之间一个重要的纽带。



常用的适配器:

1、SimpleAdapter(简单适配器):一般是与listview、hashmap构成的list一起用的,public SimpleAdapter (Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to)

第一个参数:SimpleAdapter所要运行关联到的视图,即SimpleAdapter所在的Activity

第二个参数:数据源,一般是一个List,他内部存储的则是Map或者继承自Map的对象,比如HashMap

第三个参数:资源文件,加载这个两列所需要的视图资源文件

第四个参数:主要是将Map对象中的名称映射到列名,一一对应

第五个参数:是将第四个参数的值一一对象的显示(一一对应)在接下来的int形的id数组中,这个id数组就是LayOut的xml文件中命名id形成的唯一的int型标识符。

2、BaseAdapter(基础适配器):它是一个接口类,主要用于(Spinner、ListView、GirdView),在Android的官方文档中,

public abstract class
BaseAdapter

extends ObjectimplementsListAdapter SpinnerAdapter
它的直接子类:ArrayAdapter<T>, CursorAdapter, SimpleAdapter

间接子类:
ResourceCursorAdapter, SimpleCursorAdapter
3、PagerAdapter():它是基类,该适配器能填充页面内容到ViewPager中,要实现PagerAdapter的时候,需要重写:

1、instantiateItem(ViewGroup, int)--实例化条目

2、destroyItem(ViewGroup, int, Object)--销毁条目

3、getCount()--获取条目数量

三个方法

4、ArrayAdapter():ArrayAdapter是BaseAdapter的派生类

5、BaseExpandableListAdapter():它的官方文档是这样写着的,

public abstract class
BaseExpandableListAdapter extendsObject

implements
ExpandableListAdapter,
HeterogeneousExpandableList
它是一个接口类,
6、SimpleCursorAdapter():在官方文档中,

public interface
SpinnerAdapter extends Adapter


java.lang.Object
android.widget.BaseAdapter
android.widget. SpinnerAdapter
它是这样描述的,这是一个简单的适配器,可以将静态数据映射到XML文件中定义好的视图。
一直在更新。。。。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: