A (175)

(Tuis.) #1

230 CHAPTER 7: Making Apps Interactive: Intents, Event Handling, and Menus


It is important to note that you can also create a new Java class; that is, you can access this New
Java Class dialog yourself without Eclipse doing it for you, by right-clicking on your project’s /src
folder, and selecting the New ➤ Class menu sequence, just like you did in Chapter 5, shown in
Figures 5-4 and 5-5.


Since you were creating your Galaxy class in Chapter 5, you accepted the “default” java.lang.
Object superclass for the New Java Class dialog. However, since we are now creating a new
functional screen and user interface for our app, this time we want the Android class that we’re
creating to be an Android Activity subclass, so you will need to click the Browse button next to
the Superclass data field, which will open the Superclass Selection dialog, which is shown on the
right-hand side of Figure 7-11.


In the Choose a type field, type in “activ” which will bring up all of the Activity-related classes
in Android. Notice that as you type, the selection area of the dialog will be refined in real-time in
response to every keystroke which you add. If you type the activ sequence of characters in slowly,
you will see that the selection list will decrease in size with every keystroke!


Find the Activity - android.app package option; it should now be at the top of the dialog, and is
the only option which specifies the package that it is in (because it is so commonly utilized). Next,
select it, and click the OK button, or you can double-click on it, which will insert it as your new
superclass selection.


Once you click the OK button, the Superclass Selection dialog will vanish, and you will be back
inside of your New Java Class dialog, where you can now click the Finish button, since your class
name was already defined in your Intent object constructor method call, and Eclipse filled out your
Source folder and Package fields based upon the current project and package which you are
working on (and in).


Once you click on the Finish button, Eclipse will create the EditGalaxy.java class bootstrap Java
source code for you, as is shown in Figure 7-12. Now all you have to do is to add your onCreate( )
method and start building out a new user interface design, to create your new functional Activity
screen design for your first menu option.


Figure 7-12. The EditGalaxy.java class created via the New Java Class dialog and Superclass Selection dialog

Free download pdf