Adaptor的使用
来源:互联网 发布:开机忘记密码 mac 编辑:程序博客网 时间:2024/06/06 14:26
INTRODUCING ADAPTERS
Adapters are bridging classes that bind data to Views (such as List Views) used in the user interface.
The adapter is responsible for creating the child Views used to represent each item within the parent View, and providing access to the underlying data.
Views that support Adapter binding must extend the AdapterView abstract class. It’s possible to create your own AdapterView-derived controls and to create new Adapter classes to bind them.
Introducing Some Native Adapters
In many cases you won’t have to create your own Adapter from scratch. Android supplies a set of Adapters that pump data into native UI controls.
Because Adapters are responsible both for supplying the data and for creating the Views that represent each item, Adapters can radically modify the appearance and functionality of the controls they’re bound to.
The following list highlights two of the most useful and versatile native Adapters:
➤ ArrayAdapter The Array Adapter uses generics to bind an Adapter View to an array of objects of the specified class. By default the Array Adapter uses the toString value of each object in the array to create and populate Text Views. Alternative constructors enable you to use more complex layouts, or you can extend the class to use alternatives to Text Views as
shown in the next section.
➤ SimpleCursorAdapter The Simple Cursor Adapter attaches Views specified within a layout to the columns of Cursors returned from Content Provider queries. You specify an XML layout definition, and then bind each column to a View within that layout. The adapter will create a new View for each Cursor entry and inflate the layout into it, populating each View
within the layout using the Cursor column values.
Customizing the Array Adapter
class MyAdapter1 extends BaseAdapter{
public int getCount() {
// TODO Auto-generated method stub
return igroupManager.returnUserNameListFromGroupList(gl).size();
}
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
}
LayoutInflater inflate = UserUnde.this.getLayoutInflater();
public View getView(int arg0, View arg1, ViewGroup arg2) {
View view = inflate.inflate(R.layout.deletelistson, null);
TextView deletesonTV = (TextView)view.findViewById(R.id.deletesonTV);
CheckBox deletebox = (CheckBox)view.findViewById(R.id.deletebox);
deletesonTV.setText(igroupManager.returnUserNameListFromGroupList(gl).get(arg0));
ArrayList arr = new ArrayList();
arr.add(deletebox);
arr.add(deletesonTV.getText().toString());
arraydel.add(arr);
return view;
}}
UsingAdaptersforDataBinding
int layoutID = android.R.layout.simple_list_item_1;
myAdapterInstance = new ArrayAdapter<String>(this, layoutID , myStringArray);
myListView.setAdapter(myAdapterInstance);
- Adaptor的使用
- 【简报】使用3D过渡效果的图片幻灯:Adaptor
- C++ STL Adaptor stack、queue和vector的使用
- adaptor
- Adaptor
- 创建MATLAB adaptor的项目
- 07_android入门_listView的几种Adaptor的实现_自定义的adaptor
- 无法使用Portal for ArcGIS配置ArcGIS Web Adaptor
- 写更少代码,进一步简化你ListView的Adaptor
- Stack Adaptor
- adaptor模式
- 08_android入门_listView的几种Adaptor的实现_ArrayAdapter
- 09_android入门_listView的几种Adaptor的实现_simplecursoradaptor
- 10_android入门_listView的几种Adaptor的实现_SimpleAdapter
- Web Adaptor重装配置时提示已经配置成功的问题
- FTP adaptor problem
- 设计模式-Adaptor
- Adaptor重新加载
- 一些非常有用的linux命令
- linux下用Mentohust替代锐捷
- 使用GDB调试开发板程序
- rac again 在新的机器上
- visual studio solution file *.sln文件无法双击打开解决办法
- Adaptor的使用
- SAS中的HASH语句及其常见应用
- 通讯录数据共享类ContactsContract的学习
- android的消息处理机制
- Translate:USACO/fracdec
- 片上总线Wishbone 学习(四)接口信号定义
- 使用ibatis做连接查询
- ContactsContract的学习续:联系人的增、删、查、改
- 还是不能发表文章