CHAPTER 14: Android Content Providers: Providing Data to Applications 535
Now it is time to get into the most difficult sections of this chapter—the Java code necessary to
implement the ContentProvider and ContentResolver objects to access database structures
in the Android OS.
Using the Android ContentResolver Class
Since resolving a Content Provider in Android takes more than one or two lines of code, in fact it,
will involve a “do while” type of loop to read through the database records one by one, you should
change the .finish( ) method call in the listButton object event handler to be a listGalaxyRulers( )
method call instead, as shown in Figure 14-26.
Figure 14-26. Replace the finish( ) method call with a listGalaxyRulers( ) method call and select Create Method in type
When you mouse over the currently nonexistent method and get the error message, “The method
listGalaxyRulers( ) is undefined for the type new View.OnClickListener( )”, there are two
options. The first—Create method ‘listGalaxyRulers( )’—will create an inner private method
inside of your event handler structure. The second—Create method ‘listGalaxyRulers( )’ in type
‘ContactGalaxy’—will create the standard method type (outside of the event handler method) at the
end of the class, as you have been doing thus far in the book.
You will use the second option, so that the event handler logic can call the listGalaxyRulers( )
method if it is needed. If you use the first option, only the listButton event handling structure will
be able to see and access the method code block. If you use the first option, the method will be
declared private void listGalaxyRulers( ) and it will be written underneath where it is being called in
the event handler structure, you can try this option and see if you like it. The second option declares
the method to be protected void listGalaxyRulers( ), with visibility to the rest of your class. It places
it at the bottom of your class, where all the other methods can access it if needed.