?
このドキュメントでは、 php中國語ネットマニュアル リリース
ResourceCursorAdapter
版本:Android 2.3 r1
?
結(jié)構(gòu)
繼承關(guān)系
public abstract class ResourceCursorAdapter extends CursorAdapter
????????
java.lang.Object
???????? android.widget.BaseAdapter
?????????????????? android.widget.CursorAdapter
??????????????????????????? android.widget.ResourceCursorAdapter
?
子類及間接子類
直接子類
???????? SimpleCursorAdapter
?
類概述
這是一個簡單的適配器,通過指定一個定義了視圖UI的XML文件來創(chuàng)建視圖。
?
構(gòu)造函數(shù)
?????? public?ResourceCursorAdapter?(Context?context, int layout,?Cursor?c)
???????? 構(gòu)造函數(shù)
???????? ???????? 參數(shù)
?????????????????? Context??? 與ListView相關(guān)的正在運(yùn)行的 SimpleListItemFactory上下文
?????????????????? layout?????? 一個定義了列表項視圖的布局文件資源ID,這個布局同時定義列表?????????????????????????????????????????????????? 項視圖和下拉視圖,直到你重寫它們。
?????????????????? c???????????????? 獲取數(shù)據(jù)的游標(biāo)
?
?????? public?ResourceCursorAdapter?(Context?context,int layout,?Cursor?c, boolean autoRequery)
構(gòu)造函數(shù)
???????? 參數(shù)
?????????????????? Context??? 與ListView相關(guān)的正在運(yùn)行的 SimpleListItemFactory上下文
?????????????????? layout?????? 一個定義了列表項視圖的布局文件資源ID,這個布局同時定義列表?????????????????????????????????????????????????? 項視圖和下拉視圖,直到你重寫它們。
?????????????????? c???????????????? 獲取數(shù)據(jù)的游標(biāo)
?????????????????? autoRequery??? 如果此參數(shù)為true,當(dāng)適配器的數(shù)據(jù)發(fā)生變化的時,適配器會調(diào)??????????????????????????????????????????????????????? 用游標(biāo)的requery()方法,使最新的數(shù)據(jù)始終顯示。
?
公共方法
???????? public?View?newDropDownView?(Context?context,?Cursor?cursor,?ViewGroup?parent)
生成一個新的下拉視圖來控制游標(biāo)指向的數(shù)據(jù)
?????????????????? 參數(shù)
??????????????????????????? context??? 應(yīng)用程序全局信息接口(應(yīng)用上下文)
??????????????????????????? cursor?????? 獲取數(shù)據(jù)的游標(biāo),它已經(jīng)移動到正確的位置
??????????????????????????? parent????? 與新視圖相關(guān)聯(lián)的上級視圖
?????????????????? 返回值
??????????????????????????? 新創(chuàng)建的視圖
?
???????? public?View?newView?(Context?context,?Cursor?cursor,?ViewGroup?parent)
???????? 根據(jù)指定的xml文件創(chuàng)建視圖
?????????????????? 參數(shù)
??????????????????????????? context??? 應(yīng)用程序全局信息接口(應(yīng)用上下文)
??????????????????????????? cursor?????? 獲取數(shù)據(jù)的游標(biāo),它已經(jīng)移動到正確的位置
??????????????????????????? parent????? 與新視圖相關(guān)聯(lián)的上級視圖
?????????????????? 返回值
??????????????????????????? 新創(chuàng)建的視圖
?????????????????? 參見
??????????????????????????? newView(android.content.Context,
android.database.Cursor, ViewGroup)
?
???????? public void?setDropDownViewResource?(int dropDownLayout)
???????? 設(shè)置下拉視圖相應(yīng)的布局資源
?????????????????? 參數(shù)
??????????????????????????? dropDownLayout???? 用于創(chuàng)建下拉視圖的布局資源
?
???????? public void?setViewResource?(int layout)
設(shè)置列表項視圖相應(yīng)的布局資源
?????????????????? 參數(shù)
??????????????????????????? layout?????? 用于創(chuàng)建列表項視圖的布局資源
?
補(bǔ)充
文章精選
???????? ListActivity簡介
代碼示例(ApiDemos\src\com\example\android\apis\app\QuickContactsDemo.java)
???????? Java:
???????? public class QuickContactsDemo extends ListActivity {
??? static final 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
??? };
?
??? static final int SUMMARY_ID_COLUMN_INDEX = 0;
??? static final int SUMMARY_NAME_COLUMN_INDEX = 1;
??? static final int SUMMARY_STARRED_COLUMN_INDEX = 2;
??? static final int SUMMARY_TIMES_CONTACTED_COLUMN_INDEX = 3;
??? static final int SUMMARY_PRESENCE_STATUS_COLUMN_INDEX = 4;
??? static final int SUMMARY_PHOTO_ID_COLUMN_INDEX = 5;
??? static final int SUMMARY_LOOKUP_KEY = 6;
??? static final int SUMMARY_HAS_PHONE_COLUMN_INDEX = 7;
?
?
??? @Override
??? public void 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);
?
??? }
?
??? private final class ContactListItemAdapter extends ResourceCursorAdapter {
??????? public ContactListItemAdapter(Context context, int layout, Cursor c) {
??????????? super(context, layout, c);
??????? }
?
??????? @Override
??????? public void 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);
??????????? final long 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;
??????? }
??? }
?
??? final static class ContactListItemCache {
??????? public TextView nameView;
??????? public QuickContactBadge photoView;
??????? public CharArrayBuffer nameBuffer = new CharArrayBuffer(128);
? ??}