538 CHAPTER 14: Android Content Providers: Providing Data to Applications
In the Android OS, a do-while loop begins with the keyword while and then something to evaluate.
In this case that will be whether your Cursor object, which is used to traverse or read through
the database content, has reached the end of the database. This happens when the Cursor object
reaches the last (final) record in the database and cannot read another record, much like reaching
the EOF (End Of File) character when reading a file. In pseudo-code, the do-while loop structure,
which you are going to write next, will equate to the following logic:
While (there is still another record to moveToNext to, and therefore to be able to read) Do the
things inside parens {
Create a String object to hold my Galaxy Ruler Name Data, and place the name data from a database
Column into it;
Use Android Toast Class, and its .makeText() method, to write this value to the display screen using
a long duration }
The first part of the while loop is the evaluation logic and is coded using the following line of
Java code:
while (rulerCursor.moveToNext()) { the programming logic regarding what to do as the while loop is
in progress}
As you can see in Figure 14-31, if you type the while keyword, put the rulerCursor Cursor object
inside of the evaluation parentheses, and then press the period key and type the letter “m,” you
will get a pop-up helper dialog with all of the Android Cursor class .move( ) method calls. The one
that you use in a while loop is the .moveToNext( ) method call, which is highlighted for selection in
Figure 14-31. Double-click on it to select it for use and you will be ready to code the inside of the
while loop!
Figure 14-30. The complete rulerCursor Cursor object configuration and the Eclipse warning message