232 CHAPTER 7: Making Apps Interactive: Intents, Event Handling, and Menus
Figure 7-14. Complete onOptionsItemSelected( ) method structure showing (boolean) return statements selected in Eclipse
The next step in the work process is to create the “internals” of the EditGalaxy.java class, which
when compiled becomes the EditGalaxy.class referenced inside of the Intent object. The EditGalaxy
class needs to include the onCreate( ) method, a setContentView( ) method call referencing a
RelativeLayout XML UI definition, and later on, we will add in some event handling structures, to
allow the users to interface with the UI. This will allow the application’s user to update the Galaxy
object characteristics (its data fields, or variables) by using a series of EditText widgets.
Coding the onCreate( ) Method: Using setContentView( )
The easiest way to add in the four lines of code that need to be in every Activity subclass is to simply
copy them from your MainActivity.java class, as is shown in Figure 7-15 in the top half of the screen
shot, and then change the reference to activity_main.xml to be one for activity_edit.xml, which will
“throw” an error, initially.