Using a CursorAdapter
Sometimes our data comes from a source that returns an ICursor
element; thus, we can make use of the SimpleCursorAdapter
type without having to create a collection of data objects.
How to do it...
Using the SimpleCursorAdapter
type with an ICursor
instance is almost the same as using the SimpleAdapter
type with an object collection:
When using a
CursorAdapter
type, all we need is anICursor
instance from either theContentResolver
orCursorLoader
types:var uri = ContactsContract.Contacts.ContentUri; string[] projection = { ContactsContract.Contacts.InterfaceConsts.Id, ContactsContract.Contacts.InterfaceConsts.DisplayName, ContactsContract.Contacts.InterfaceConsts .ContactStatusLabel, }; ICursor cursor = ContentResolver.Query( uri, projection, null, null, null);
Once we have the cursor, we can hand it over to the
SimpleCursorAdapter
type, which is very similar to theSimpleAdapter
type:SimpleCursorAdapter adapter = new SimpleCursorAdapter( this, Android.Resource...