COEN268-Exercise1 - Exercise#1 Android Application Development Advanced Hello World App 1 Create a new Android Project 1 Open Android Studio 2 Click the

COEN268-Exercise1 - Exercise#1 Android Application...

This preview shows page 1 - 4 out of 8 pages.

Exercise #1 Android Application Development Advanced Hello World App 1. Create a new Android Project 1. Open Android Studio 2. Click the menu File -> New -> Project . 3. Name the Application Ex1 Fill in the properties: x Application Name = Ex1 x Package Name = edu.scu.android.ex1 x Create Activity = Ex1Activity x Minimum SDK = 8 4. Choose a Blank Activity and name it Ex1Activity 5. Click “ Finish .” 2. Run "Hello World" on the Emulator Before we can run the application, we need to setup an Android Virtual Device (AVD), or emulator, to run it on: x Select the menu Tools -> Android -> AVD Manager .” x Click the Create button. x Give your AVD a name. x Select the target build that we would like to run the application on. x Click Create AVD and close out the AVD Manager. We’ re now ready to run our application. x Select the menu Run -> Run Note: The emulator may take a long time to start up. Another way to run your application is to right-click on the project in the Package Explorer, then select Run As -> Android Application . You can interact with the emulator using the mouse just like you would with a device. To get started, press the Menu
Image of page 1
key to see the home screen. Congratulations! You've just created and an Android Application. 3. Getting the User’s Name To get the user’ s name, you will be creating an Activity class, which will allow the user to enter their name into a text field and press a button when finished to proceed to the ”Hello” greeting Activity. There are three separate steps to accomplish here. You must first layout your user interface in XML. Then you must create the Activity class to parse the input from the user and initiate the Ex1 Activity. Finally, you will have to reconfigure the application to use your new name retrieval Activity on startup. 4. Create a New Activity Class x Create a new class that extends android.app.Activity class and implements android.view.View.OnClickListener interface. Implement the OnClickListener interface by creating a method stub with the following signature: public void onClick(View v). We'll fill in this method later. The new class will look like this: package edu.scu.android.ex1; public class GetName { } Modify it so it extends Activity & implements android.view.View.OnClickListener: The finished class code looks like this so far: package edu.scu.android.ex1; import android.app.Activity; import android.view.View; public class GetName extends Activity implements android.view.View.OnClickListener{ public void onClick(View arg0) { // TODO Auto-generated method stub } }
Image of page 2
x Declare a data member of type android.widget.EditText like this: android.widget.EditText name; This will hold a reference to the text field in which the user will enter their name, the same one that you added to the name_getter.xml layout file.
Image of page 3
Image of page 4

You've reached the end of your free preview.

Want to read all 8 pages?

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture