A (175)

(Tuis.) #1
CHAPTER 14: Android Content Providers: Providing Data to Applications 539

Inside of your while loop construct, inside of those { } curly braces, is the Java programming logic
that will be executed during each “pass” of the loop. The while loop will continue to execute these
statements as long as your Cursor object finds data records inside of a database that it can read,
that is, until it reaches the last data record. The first line of Java code declares a String object.
Name it rulerName and set it equal to the ruler name data in the database by calling a .getString( )
method, off of the rulerCursor object, and calling a .getColumnIndex( ) method off of the same
object inside of the .getString( ) method call to read the database, as seen in Figure 14-32:


String rulerName = rulerCursor.getString(rulerCursor.getColumnIndex(ContactsContract.Contacts.
DISPLAY_NAME_PRIMARY));


Figure 14-31. Create a while loop structure, and in the evaluation part of the loop, call .moveToNext( ) off rulerCursor


Figure 14-32. Inside the while loop create a String object named rulerName, load it with .getString( ), and Toast it

Free download pdf