Reading from a database
Before the record added in the previous step can be displayed, the app must have the
capability to read the records from the database. First, the database must be queried
for the records to display. Then, you will use a tool called the
Cursor
to iterate
through the records and add them to a list.
Understanding the cursor
In Android, a
Cursor
is assigned to the result set of a query being run against the
database. The
Cursor
is then used to iterate over the result set in a type-safe
manner. It iterates through the result set
row by row
,
field by field
.
Internally, the rows of data that are returned by a query are stored in the
Cursor
reads through the data-keeping track of its current position. To start iterating, the
current position must be moved to point to a valid row of data, such as the first row.
Then a loop structure is utilized to keep reading while a next record exists, to read in
the result set.
In the
Do'stlaringiz bilan baham: |