Children's shoes using SQLite database should be no stranger to cursor, if you are engaged in. NET development you can interpret the cursor as a collection of data in ADO, which is equivalent to DataReader. Today, I'm going to take it out alone to deepen my understanding of using Cursor in Android.
About Cursor
When you understand and use the Android cursor, you must first know a few things about the cursor:
The Cursor is a collection of each row.
Use Movetofirst () to locate the first row.
Use MoveToNext () to navigate to the next line, returning a Boolean type
You must know the name of each column.
You must know the data type of each column.
The Cursor is a random data source.
All data is obtained by subscript.
Example:
The query () method actually splits the SELECT statement into several components and then acts as an input parameter to the method:
Sqlitedatabase db =databasehelper.getwritabledatabase (); Cursor Cursor= Db.query ("Person",Newstring[]{"Personid,name,age"}, "name like?",Newstring[]{% "%"},NULL,NULL, "PersonID desc", "a"); String columnnmaes[]=Cursor.getcolumnnames (); String ColumnName; String name; intPersonID; intAge ; while(Cursor.movetonext ()) { for(inti = 0; i < columnnmaes.length; i++) {ColumnName=Columnnmaes[i]; if(columnname=="No.") PersonID=Cursor.getint (i); if(columnname=="name") name=Cursor.getint (i); if(columnname=="Age")=Cursor.getint (i); }} cursor.close (); Db.close ();
Android Development Note "Sqlite Cursor use"