The cursor in the mono for Android is identified by the ICursor interface, which exposes all methods of manipulating the resulting data set. The use of the cursor consumes system resources very much, so it should be light than the cursor when not in use. The Startmanagingcursor method allows the application to manage cursors. The example shows the history of the user's browsing URLs through spinner, which gets the data through a system-provided content provider, and more content providers reference the Android development documentation http://developer.android.com/reference/ Android/provider/package-summary.html.
Note: Add the appropriate permissions
Define the Initspinner method in the activity to initialize the spinner object and the associated adapter and adapter views. Private void Initspinner ()
{Spinner= findviewbyid<spinner>(Resource.Id.spinner); //define the variable to determine the selection, avoid the initial data will go itemselected intlastspinnerselectedpositon=0; //using the system-supplied adapter view template SimplespinneritemSimplecursoradapter SpinnerAdapter1 =NewSimplecursoradapter ( This, Android.resource.layout.simplespinneritem,getbookmarkcursor (),New string[]{Browser.BookmarkColumns.Title},New int[]{Android.Resource.Id.Text1}]; //Get Contact person//simplecursoradapter spinnerAdapter2 = new Simplecursoradapter (This,android.resource.layout.simplespinneritem, Getcontacts (),//new string[]{ContactsContract.ContactsColumns.DisplayName},new int[]{Android.Resource.Id.Text1}); //Specifies the style of the spinner pop-up selection listSpinneradapter1.setdropdownviewresource (Android.Resource.Layout.SimpleSpinnerDropDownItem); Spinner. Adapter=SpinnerAdapter1; //spinner. Prompt = "Select Open url";Spinner. itemselected+= (Objectsender, Adapterview.itemselectedeventargs e) = = { varCurselectedindex =spinner. Selecteditemposition; //To avoid the execution of methods when initializing data if(curselectedindex!=Lastspinnerselectedpositon) {Android.Database.ICursor SelectedItem=(Android.Database.ICursor) spinner. SelectedItem; varWEBURL =selecteditem.getstring (Selecteditem.getcolumnindex (BROWSER.BOOKMARKCOLUMNS.URL));
Open the specified URL by intent Intent browerintent=NewIntent (Intent.actionview); Browerintent.setdata (Android.Net.Uri.Parse (WEBURL)); StartActivity (browerintent); /*Intent callintent = new Intent (Intent.actioncall,android.net.uri.parse ("tel:10086")); StartActivity (callintent);*/Lastspinnerselectedpositon=Curselectedindex; } }; }
Create a Simplecursoradapter object that provides data through the Getbookmarkcursor method, and the main function of the method is to query the content provider through the activity class's Managedquery method, avoiding the direct management of the cursor.
Introduction to parameters and return values
Parameters:
Uri , which is used for the URI of the Content Provider query, that is, to fetch data from this URI. For example:
Uri uri = Contacts.People.CONTENT_URI; //Contact list URI.
projectionthat identifies which columns in the URI need to be included in the returned Cursor object. For example:
Columns to query
string[] projection = {Contacts.PeopleColumns.NAME, Contacts.PeopleColumns.NOTES};
selection, as the filter parameter of the query (filtering out the data that conforms to selection), is similar to the conditional selection after the Where statement in SQL. For example:
String selection = Contacts.People.NAME + "=?" //Query criteria
Selectionargs , query condition parameters, used with selection parameters. For example:
String[] Selectionargs = {"Braincol", "Nixn.dev"}; //Query condition Parameters
SortOrder , sort the query results by a column in the query columns ( columns in the projection parameter). For example:
String sortOrder = Contacts.PeopleColumns.NAME; //How the query results are sorted (sorted by the specified query column)
return value:
A Cursor object that contains the specified data.
Getbookmarkcursor Method implementation
Private Android.Database.ICursor getbookmarkcursor () { // get Data through a system-provided content provider return Managedquery (Browser.bookmarksuri,newstring[]{Browser.BookmarkColumns.Title, Browser.bookmarkcolumns.url,browser.bookmarkcolumns.interfaceconsts.id},null,null, NULL ); }