Simplecursoradapter () is the constructor of the simplecursoradapter class.
Description:
Simplecurosradapter is a simple adapter that matches columns in cursor with textviews or imageviews defined in the XML file. You can specify columns in cursor, views used to display these columns, and XML files defining these views.
That is to say, simplecursoradapter allows you to bind the columns of a cursor to the listview and display each item in the list using a custom layout.
Simplecursoradapter can be used as an intermediate bridge to directly display the data queried from the SQLite database to the listview.
Prototype:
PublicSimplecursoradapter (context,IntLayout, cursor C, string [] from,Int[] ){
Super(Context, layout, C );
MTO =;
Moriginalfrom = from;
Findcolumns (from );
}
Parameters:
ContextThe context of the listview associated with simplelistitemfactory ). That is, the activity of the listview.
Int layout,Displays the layout file of the list item. The layout file must at least contain the views named in the "to" parameter.
Cursor C,Database cursor (cursor ). If cursor is invalid, this parameter can be null.
String [] FromSpecifies which columns of the column will be bound (displayed) to the UI. If cursor is invalid, this parameter can be null.
Int []To display views of the Data List specified by the "from" parameter. All views must be textviews. The first N values of the "from" parameter (valus) correspond to the first n views of the "to" parameter. If cursor is invalid, this parameter can be null.
Example:
Uri uri = contacts. People. content_uri;
String [] projection = {contacts. peoplecolumns. Name,
Contacts. peoplecolumns. Notes };
String selection = contacts. peoplecolumns. Name +"=? ";
String [] selectionargs = {"Braincol","Nixn. Dev"};
String sortorder = contacts. peoplecolumns. Name;
// Use managedquery to obtain the contacts. People contentprovider's cursor.
Cursor cursor = managedquery (Uri, projection, selection, selectionargs, sortorder );
// Use simplecursoradapter to create a cursor Adapter. The data representation is name-notes.
Simplecursoradapter adapter =NewSimplecursoradapter (This, R. layout. contact_list_item,
Cursor,NewString [] {contactcolumn. Name, contactcolumn. Notes },
New Int[] {R. Id. Name, R. Id. Notes });
// Associate the adapter with the current listview