Android API: simplecursoradapter ()

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.