Android 中文API(86)——ResourceCursorAdapter
来源:互联网 发布:网络认证系统 编辑:程序博客网 时间:2024/05/18 11:49
转自"HalZhang",http://www.cnblogs.com/halzhang
一、结构
public abstract class ResourceCursorAdapterextends CursorAdapter
java.lang.Object
android.widget.BaseAdapter
android.widget.CursorAdapter
android.widget.ResourceCursorAdapter
直接子类
SimpleCursorAdapter
二、概述
这是一个简单的适配器,通过指定一个定义了视图UI的XML文件来创建视图。
三、构造函数
publicResourceCursorAdapter(Contextcontext, int layout,Cursorc)
构造函数
参数
Context 与ListView相关的正在运行的 SimpleListItemFactory上下文
layout 一个定义了列表项视图的布局文件资源ID,这个布局同时定义列表项视图和下拉视图,直到你重写它们。
c 获取数据的游标
publicResourceCursorAdapter(Context context,int layout, Cursor c, boolean autoRequery)
构造函数
参数
Context 与ListView相关的正在运行的 SimpleListItemFactory上下文
layout 一个定义了列表项视图的布局文件资源ID,这个布局同时定义列表项视图和下拉视图,直到你重写它们。
c 获取数据的游标
autoRequery 如果此参数为true,当适配器的数据发生变化的时,适配器会调用游标的requery()方法,使最新的数据始终显示。
四、公共方法
publicView newDropDownView(Context context, Cursorcursor, ViewGroup parent)
生成一个新的下拉视图来控制游标指向的数据
参数
context 应用程序全局信息接口(应用上下文)
cursor 获取数据的游标,它已经移动到正确的位置
parent 与新视图相关联的上级视图
返回值
新创建的视图
publicView newView(Context context, Cursorcursor, ViewGroup parent)
根据指定的xml文件创建视图
参数
context 应用程序全局信息接口(应用上下文)
cursor 获取数据的游标,它已经移动到正确的位置
parent 与新视图相关联的上级视图
返回值
新创建的视图
参见
newView(android.content.Context, android.database.Cursor, ViewGroup)
public voidsetDropDownViewResource(int dropDownLayout)
设置下拉视图相应的布局资源
参数
dropDownLayout 用于创建下拉视图的布局资源
public voidsetViewResource(int layout)
设置列表项视图相应的布局资源
参数
layout 用于创建列表项视图的布局资源
五、补充
文章精选
ListActivity简介
staticfinal String[] CONTACTS_SUMMARY_PROJECTION= new String[] {
Contacts._ID, // 0
Contacts.DISPLAY_NAME, // 1
Contacts.STARRED, // 2
Contacts.TIMES_CONTACTED, // 3
Contacts.CONTACT_PRESENCE, // 4
Contacts.PHOTO_ID, // 5
Contacts.LOOKUP_KEY, // 6
Contacts.HAS_PHONE_NUMBER, // 7
};
staticfinalint SUMMARY_ID_COLUMN_INDEX= 0;
staticfinalint SUMMARY_NAME_COLUMN_INDEX= 1;
staticfinalint SUMMARY_STARRED_COLUMN_INDEX= 2;
staticfinalint SUMMARY_TIMES_CONTACTED_COLUMN_INDEX= 3;
staticfinalint SUMMARY_PRESENCE_STATUS_COLUMN_INDEX= 4;
staticfinalint SUMMARY_PHOTO_ID_COLUMN_INDEX= 5;
staticfinalint SUMMARY_LOOKUP_KEY= 6;
staticfinalint SUMMARY_HAS_PHONE_COLUMN_INDEX= 7;
@Override
publicvoid onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String select ="(("+ Contacts.DISPLAY_NAME+ " NOTNULL) AND ("
+ Contacts.HAS_PHONE_NUMBER+ "=1) AND ("
+ Contacts.DISPLAY_NAME+ " != '' ))";
Cursor c =
getContentResolver().query(Contacts.CONTENT_URI, CONTACTS_SUMMARY_PROJECTION, select,
null, Contacts.DISPLAY_NAME+ " COLLATE LOCALIZED ASC");
startManagingCursor(c);
ContactListItemAdapter adapter =new ContactListItemAdapter(this, R.layout.quick_contacts, c);
setListAdapter(adapter);
}
privatefinalclass ContactListItemAdapterextends ResourceCursorAdapter {
public ContactListItemAdapter(Context context,int layout, Cursor c) {
super(context, layout, c);
}
@Override
publicvoid bindView(View view, Context context, Cursor cursor) {
final ContactListItemCache cache= (ContactListItemCache) view.getTag();
TextView nameView = cache.nameView;
QuickContactBadge photoView = cache.photoView;
// Set the name
cursor.copyStringToBuffer(SUMMARY_NAME_COLUMN_INDEX, cache.nameBuffer);
int size= cache.nameBuffer.sizeCopied;
cache.nameView.setText(cache.nameBuffer.data, 0, size);
finallong contactId= cursor.getLong(SUMMARY_ID_COLUMN_INDEX);
final String lookupKey= cursor.getString(SUMMARY_LOOKUP_KEY);
cache.photoView.assignContactUri(Contacts.getLookupUri(contactId, lookupKey));
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View view =super.newView(context, cursor, parent);
ContactListItemCache cache =new ContactListItemCache();
cache.nameView = (TextView) view.findViewById(R.id.name);
cache.photoView = (QuickContactBadge) view.findViewById(R.id.badge);
view.setTag(cache);
return view;
}
}
finalstaticclass ContactListItemCache {
public TextView nameView;
public QuickContactBadge photoView;
public CharArrayBuffer nameBuffer= new CharArrayBuffer(128);
}
}
- Android 中文API(86)——ResourceCursorAdapter
- Android 中文API(86)——ResourceCursorAdapter
- Android7.0中文文档(API)-- ResourceCursorAdapter
- ResourceCursorAdapter
- Android—API中文文档
- Android API 中文 — ListView
- <转>Android API 中文(13) —— ToggleButton
- <转>Android API 中文(14) —— ViewStub
- Android API 中文 (15) —— GridView
- <转>Android 中文 API (16) —— AnalogClock
- <转>Android 中文 API (17) —— TextSwitcher
- <转>Android 中文 API (18) —— AbsSeekBar
- <转>Android 中文 API (19) —— TwoLineListItem
- <转>Android 中文 API (20) —— DatePicker
- Android 中文 API (28) —— CheckedTextView
- Android中文API(130) —— Html
- Android API 中文 (53) —— BaseAdapter
- android api 中文 (75)—— AdapterView.OnItemClickListener
- 写的一个mysqli类,带cache,讨论下filecache和mysql本身的效率
- WPF 显示时间
- ANDRIOD开题及其环境配置篇
- mac osx10.7 xcode4.3.2 uploader提交时末知错误(An error occurred uploading to the iTunes store) 的解决办法
- android音乐播放器(改进版)
- Android 中文API(86)——ResourceCursorAdapter
- computer science themes
- MATLAB命令大全
- C++读写数据0A强制转换为0d0a
- UC回顾 2012/04/06
- Android Picture和PictureDrawable的用处
- Red Hat Cluster Suite 组件 fencing FAQ
- 不觉春至
- Winform datagridview使用技巧