Verzeichnis suchen
android Manifest Manifest.permission Manifest.permission_group android.accessibilityservice AccessibilityService android.accounts Account android.app NotificationManager android.bluetooth BluetoothAdapter BluetoothClass BluetoothClass.Device BluetoothClass.Device.Major BluetoothClass.Service BluetoothDevice BluetoothServerSocket BluetoothSocket android.content SharedPreferences android.database.sqlite SQLiteCursorDriver SQLiteOpenHelper android.graphics Bitmap android.location LocationListener Geocoder GpsStatus GpsStatus.Listener GpsStatus.NmeaListener GpsSatellite android.media AudioFormat AsyncPlayer AudioRecord AudioRecord.OnRecordPositionUpdateListener ThumbnailUtils AudioManager android.net TrafficStats MailTo LocalSocket android.os AsyncTask AsyncTask.Status CountDownTimer Message MessageQueue HandlerThread android.text Html android.util JsonWriter android.view ContextMenu ContextMenu.ContextMenuInfo Display ViewManager View ViewStub ViewTreeObserver ViewParent WindowManager GestureDetector Gravity MenuInflater ScaleGestureDetector SoundEffectConstants android.view.inputmethod InputConnection InputMethod InputMethodSession BaseInputConnection InputMethodManager android.widget AbsListView AbsListView.LayoutParams AbsListView.OnScrollListener AbsListView.RecyclerListener AbsoluteLayout AbsoluteLayout.LayoutParams AbsSeekBar AbsSpinner AdapterView AdapterView.AdapterContextMenuInfo AdapterView.OnItemLongClickListener AdapterView.OnItemSelectedListener AdapterView.OnItemClickListener AnalogClock BaseAdapter BaseExpandableListAdapter Button CheckBox CheckedTextView Checkable Chronometer Chronometer.OnChronometerTickListener CompoundButton CompoundButton.OnCheckedChangeListener CursorAdapter CursorTreeAdapter DatePicker DatePicker.OnDateChangedListener DialerFilter DigitalClock EditText Filter Filter.FilterListener Filter.FilterResults ExpandableListAdapter ExpandableListView.OnChildClickListener ExpandableListView.OnGroupClickListener ExpandableListView.OnGroupCollapseListener ExpandableListView.OnGroupExpandListener Filterable Gallery Gallery.LayoutParams GridView GridLayout GridLayout.Alignment RadioGroup ImageView ImageView.ScaleType HorizontalScrollView ImageButton ImageSwitcher FilterQueryProvider ListAdapter ListView MediaController MultiAutoCompleteTextView MultiAutoCompleteTextView.CommaTokenizer MultiAutoCompleteTextView.Tokenizer QuickContactBadge RadioButton RatingBar RatingBar.OnRatingBarChangeListener RelativeLayout RemoteViews ResourceCursorAdapter ResourceCursorTreeAdapter Scroller ScrollView SearchView SearchView.OnCloseListener SearchView.OnQueryTextListener SearchView.OnSuggestionListener SeekBar SeekBar.OnSeekBarChangeListener SimpleAdapter SimpleAdapter.ViewBinder SimpleCursorAdapter SimpleCursorAdapter.CursorToStringConverter SimpleCursorAdapter.ViewBinder SimpleCursorTreeAdapter SimpleCursorTreeAdapter.ViewBinder SimpleExpandableListAdapter SlidingDrawer SlidingDrawer.OnDrawerCloseListener SlidingDrawer.OnDrawerOpenListener SlidingDrawer.OnDrawerScrollListener Spinner SpinnerAdapter WrapperListAdapter TabHost TabHost.TabSpec TextView TimePicker TimePicker.OnTimeChangedListener Toast TableLayout TableLayout.LayoutParams TableRow TableRow.LayoutParams TabWidget TextSwitcher ToggleButton TwoLineListItem VideoView ViewAnimator ViewFlipper ViewSwitcher ViewSwitcher.ViewFactory ZoomButtonsController ZoomButtonsController.OnZoomListener ZoomButton ZoomControls dalvik.system DexFile
Figuren


ResourceCursorAdapter

版本:Android 2.3 r1

 

结构

继承关系

public abstract class ResourceCursorAdapter extends CursorAdapter

        

java.lang.Object

         android.widget.BaseAdapter

                   android.widget.CursorAdapter

                            android.widget.ResourceCursorAdapter

 

子类及间接子类

直接子类

         SimpleCursorAdapter

 

类概述

这是一个简单的适配器,通过指定一个定义了视图UIXML文件来创建视图。

 

构造函数

       public ResourceCursorAdapter (Context context, int layout, Cursor c)

         构造函数

                  参数

                   Context    ListView相关的正在运行的 SimpleListItemFactory上下文

                   layout       一个定义了列表项视图的布局文件资源ID,这个布局同时定义列表                                                   项视图和下拉视图,直到你重写它们。

                   c                 获取数据的游标

 

       public ResourceCursorAdapter (Context context,int layout, Cursor c, boolean autoRequery)

构造函数

         参数

                   Context    ListView相关的正在运行的 SimpleListItemFactory上下文

                   layout       一个定义了列表项视图的布局文件资源ID,这个布局同时定义列表                                                   项视图和下拉视图,直到你重写它们。

                   c                 获取数据的游标

                   autoRequery    如果此参数为true,当适配器的数据发生变化的时,适配器会调                                                        用游标的requery()方法,使最新的数据始终显示

 

公共方法

         public View newDropDownView (Context context, Cursor cursor, ViewGroup parent)

生成一个新的下拉视图来控制游标指向的数据

                   参数

                            context    应用程序全局信息接口(应用上下文)

                            cursor       获取数据的游标,它已经移动到正确的位置

                            parent      与新视图相关联的上级视图

                   返回值

                            新创建的视图

 

         public View newView (Context context, Cursor cursor, ViewGroup parent)

         根据指定的xml文件创建视图

                   参数

                            context    应用程序全局信息接口(应用上下文)

                            cursor       获取数据的游标,它已经移动到正确的位置

                            parent      与新视图相关联的上级视图

                   返回值

                            新创建的视图

                   参见

                            newView(android.content.Context, android.database.Cursor, ViewGroup)

 

         public void setDropDownViewResource (int dropDownLayout)

         设置下拉视图相应的布局资源

                   参数

                            dropDownLayout     用于创建下拉视图的布局资源

 

         public void setViewResource (int layout)

设置列表项视图相应的布局资源

                   参数

                            layout       用于创建列表项视图的布局资源

 

补充

文章精选

         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);

    }


Vorheriger Artikel: Nächster Artikel: