The cursor and its adapter mode

Source: Internet
Author: User

1.public Interface Cursor

|-android.database.cursor

The cursor is generally used to store the collection of query results , especially the return value of the database's query method is the cursor object, and the cursor object holds the result of the query. Similar to iterator iterators.

Common methods:

Movetofirst ();//This method causes cursor cursors to point to the first row of the data record, which is used to iterate from the first line

MoveToNext ();//Determine if the next row has a record, and then point to the next line.

Xxxx getxxxx(int columnindex);//Based on columnindex, gets the value of XXX data type,

int Getcolumnindexorthrow (String columnName)//gets its index value based on the column name

Note: You can use the activity's Startmanagingcursor (cursor) method to manage the life cycle of the created cursor so that it is easy to reclaim and destroy the cursor.

Case:

XXXX getxxxx (Getcolumnindexorthrow (String columnName));//based on the column name, gets the value (XXXX) on the column name on the table;

Traverse:

Cursor.movetofirst ()

while (Cursor.movetonext ())

{

Cursor.xxx ();//Traversal result set

}

2.public Abstract class CursorAdapter

Extends Baseadapter
Implements Filterable

Subclass is the following two sub-classes

When implementing CursorAdapter, you implement the following abstract methods:

     //Create a new View object@Override PublicView Newview (context context, cursor cursor, viewgroup parent) {View View=Super. Newview (context, cursor, parent); Tag Tag=NewTag (); Tag.icon=(ImageView) View.findviewbyid (R.id.book_icon); Tag.author=(TextView) View.findviewbyid (R.id.author); Tag.name=(TextView) View.findviewbyid (r.id.book_name); Tag.year=(TextView) View.findviewbyid (r.id.year);            View.settag (tag); returnview; }      //bind the data that the cursor points to and the View object that is created@Override Public voidBindView (view view, context context, cursor cursor) {tag tag=(TAG) View.gettag ();            Tag.author.setText (cursor.getstring (cursor. Getcolumnindexorthrow (Publisher.AUTHOR.NAME)));            Tag.name.setText (cursor.getstring (cursor. Getcolumnindexorthrow (Publisher.BOOK.NAME)));            Tag.year.setText (cursor.getstring (cursor. Getcolumnindexorthrow (Publisher.BOOK.PUBLISH_YEAR))); Bitmap icon=Bitmapfactory.decoderesource (Getresources (), R.drawable.icon);        Tag.icon.setImageBitmap (icon); }     //A collection of various UI components inside the view   classTag { PublicImageView icon;  PublicTextView name;  PublicTextView author;  PublicTextView Year; }

3.public Abstract class Resourcecursoradapter

Function: The cursor data is displayed on the view via the adapter

Resourcecursoradapter (context context, int layout, Cursor c)

4.public class Simplecursoradapter

Simplecursoradapter (context context, int layout, Cursor C, string[] from, int[] to)

The cursor and its adapter mode

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.