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:

  1. When using a CursorAdapter type, all we need is an ICursor instance from either the ContentResolver or CursorLoader types:
    var uri = ContactsContract.Contacts.ContentUri; string[] projection = { ContactsContract.Contacts.InterfaceConsts.Id, ContactsContract.Contacts.InterfaceConsts.DisplayName, ContactsContract.Contacts.InterfaceConsts .ContactStatusLabel, }; ICursor cursor = ContentResolver.Query( ...

Get Xamarin Mobile Development for Android Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.