Android Hello World
description
Transcript of Android Hello World
![Page 1: Android Hello World](https://reader035.fdocuments.us/reader035/viewer/2022062314/5681394e550346895da0e9ce/html5/thumbnails/1.jpg)
Android Hello World
1
![Page 2: Android Hello World](https://reader035.fdocuments.us/reader035/viewer/2022062314/5681394e550346895da0e9ce/html5/thumbnails/2.jpg)
Click on Start and type eclipse into the textbox
2
![Page 3: Android Hello World](https://reader035.fdocuments.us/reader035/viewer/2022062314/5681394e550346895da0e9ce/html5/thumbnails/3.jpg)
You can right click on the icon and choose Pin to Start Menu for easier access later
3
![Page 4: Android Hello World](https://reader035.fdocuments.us/reader035/viewer/2022062314/5681394e550346895da0e9ce/html5/thumbnails/4.jpg)
Click on the icon, you will be prompted to choose a workspace (where your programs will go). You can make your choice the default. Click OK.
4
![Page 5: Android Hello World](https://reader035.fdocuments.us/reader035/viewer/2022062314/5681394e550346895da0e9ce/html5/thumbnails/5.jpg)
Your first time on a machine, you will prompted to designate the location of the Android SDK in preferences
5
![Page 6: Android Hello World](https://reader035.fdocuments.us/reader035/viewer/2022062314/5681394e550346895da0e9ce/html5/thumbnails/6.jpg)
Click on Browse, choose Computer/C:/Android-sdks
6
![Page 7: Android Hello World](https://reader035.fdocuments.us/reader035/viewer/2022062314/5681394e550346895da0e9ce/html5/thumbnails/7.jpg)
Click Apply and OK.
7
![Page 8: Android Hello World](https://reader035.fdocuments.us/reader035/viewer/2022062314/5681394e550346895da0e9ce/html5/thumbnails/8.jpg)
Start a new Project Method 1: File/New/Android Application Project
8
![Page 9: Android Hello World](https://reader035.fdocuments.us/reader035/viewer/2022062314/5681394e550346895da0e9ce/html5/thumbnails/9.jpg)
Start a new Project Method 2: File/New/Project, then in the dialog choose Android/Android Application Project
9
![Page 10: Android Hello World](https://reader035.fdocuments.us/reader035/viewer/2022062314/5681394e550346895da0e9ce/html5/thumbnails/10.jpg)
Fill in the fields of the dialog: Application Name, Project Name, Package Name. For now I made the Minimum Required SDK and Target SDK the same. Click Next.
10
![Page 11: Android Hello World](https://reader035.fdocuments.us/reader035/viewer/2022062314/5681394e550346895da0e9ce/html5/thumbnails/11.jpg)
Accept defaults on next few dialogs. Next. Next.
11
![Page 12: Android Hello World](https://reader035.fdocuments.us/reader035/viewer/2022062314/5681394e550346895da0e9ce/html5/thumbnails/12.jpg)
More dialogs. Next. Finish.
12
![Page 13: Android Hello World](https://reader035.fdocuments.us/reader035/viewer/2022062314/5681394e550346895da0e9ce/html5/thumbnails/13.jpg)
Click on the resource (res) folder, the layout folder, the activity_main.xml file. Then click on the Graphical Layout tab to see what the “screen” will look like
13
![Page 14: Android Hello World](https://reader035.fdocuments.us/reader035/viewer/2022062314/5681394e550346895da0e9ce/html5/thumbnails/14.jpg)
Click on Window/Android Virtual Device Manager
14
![Page 15: Android Hello World](https://reader035.fdocuments.us/reader035/viewer/2022062314/5681394e550346895da0e9ce/html5/thumbnails/15.jpg)
Click New ….
15
![Page 16: Android Hello World](https://reader035.fdocuments.us/reader035/viewer/2022062314/5681394e550346895da0e9ce/html5/thumbnails/16.jpg)
Supply a name, choose a device to emulate, a target version of Android and a CPU (typically Atom or ARM). Click OK.
If an option you wanted is missing. You may need to go to Windows/Android SDK Manager and download it. After that you should probably restart Eclipse.
16
![Page 17: Android Hello World](https://reader035.fdocuments.us/reader035/viewer/2022062314/5681394e550346895da0e9ce/html5/thumbnails/17.jpg)
Click on the drop-down arrow next to the green Run as arrow. Choose Run Configuration
17
![Page 18: Android Hello World](https://reader035.fdocuments.us/reader035/viewer/2022062314/5681394e550346895da0e9ce/html5/thumbnails/18.jpg)
Double click on Android Application on the left panel. Then click on Browse to choose the project to run
18
![Page 19: Android Hello World](https://reader035.fdocuments.us/reader035/viewer/2022062314/5681394e550346895da0e9ce/html5/thumbnails/19.jpg)
Then click on the Target tab and choose the AVD to use for the emulation. Click Apply and Run.
19
![Page 20: Android Hello World](https://reader035.fdocuments.us/reader035/viewer/2022062314/5681394e550346895da0e9ce/html5/thumbnails/20.jpg)
The emulator starting – this sometimes takes a long time!
20
![Page 21: Android Hello World](https://reader035.fdocuments.us/reader035/viewer/2022062314/5681394e550346895da0e9ce/html5/thumbnails/21.jpg)
Emulated Hello World project
21
![Page 22: Android Hello World](https://reader035.fdocuments.us/reader035/viewer/2022062314/5681394e550346895da0e9ce/html5/thumbnails/22.jpg)
Drag a Button onto the layout
22
![Page 23: Android Hello World](https://reader035.fdocuments.us/reader035/viewer/2022062314/5681394e550346895da0e9ce/html5/thumbnails/23.jpg)
Click on the activity_main.xml tab to see the effect in XML code
23
![Page 24: Android Hello World](https://reader035.fdocuments.us/reader035/viewer/2022062314/5681394e550346895da0e9ce/html5/thumbnails/24.jpg)
Return to Graphical Layout and change the id and the Text in the Properties area
24
![Page 25: Android Hello World](https://reader035.fdocuments.us/reader035/viewer/2022062314/5681394e550346895da0e9ce/html5/thumbnails/25.jpg)
Drag a TextView from the Form Widgets onto the layout
25
![Page 26: Android Hello World](https://reader035.fdocuments.us/reader035/viewer/2022062314/5681394e550346895da0e9ce/html5/thumbnails/26.jpg)
Change the id and Text in the Properties area
26
![Page 27: Android Hello World](https://reader035.fdocuments.us/reader035/viewer/2022062314/5681394e550346895da0e9ce/html5/thumbnails/27.jpg)
Expand src and the package, click on MainActivityJava. Also click on the MainActivity.java tab at the top
27
![Page 28: Android Hello World](https://reader035.fdocuments.us/reader035/viewer/2022062314/5681394e550346895da0e9ce/html5/thumbnails/28.jpg)
Click on the Save All icon
28
![Page 29: Android Hello World](https://reader035.fdocuments.us/reader035/viewer/2022062314/5681394e550346895da0e9ce/html5/thumbnails/29.jpg)
Inside the onCreate method in the MainActivity class add the line of code Button btnClickMe = (Button) findViewById(id.btnClickMe)
29
![Page 30: Android Hello World](https://reader035.fdocuments.us/reader035/viewer/2022062314/5681394e550346895da0e9ce/html5/thumbnails/30.jpg)
Place the mouse over the red squiggly underlined Button and choose Import Button
30
![Page 31: Android Hello World](https://reader035.fdocuments.us/reader035/viewer/2022062314/5681394e550346895da0e9ce/html5/thumbnails/31.jpg)
Expand the Imports to see the result
31
![Page 32: Android Hello World](https://reader035.fdocuments.us/reader035/viewer/2022062314/5681394e550346895da0e9ce/html5/thumbnails/32.jpg)
Associate an setOnClickListener with the Button. Type btnClickMe.setOnClickListener(new OnClickListener(){ });
32
This action causes two problems. The first is cured by another import – This time import android.view.View.OnClickListener I had trouble choosing the Import from the list and just ended up Typing it in up in the Import area
![Page 33: Android Hello World](https://reader035.fdocuments.us/reader035/viewer/2022062314/5681394e550346895da0e9ce/html5/thumbnails/33.jpg)
The second problem is cured by adding the unimplemented onClick method
33
![Page 34: Android Hello World](https://reader035.fdocuments.us/reader035/viewer/2022062314/5681394e550346895da0e9ce/html5/thumbnails/34.jpg)
Put the code you want executed when the user clicks the button inside the onClick method
34
![Page 35: Android Hello World](https://reader035.fdocuments.us/reader035/viewer/2022062314/5681394e550346895da0e9ce/html5/thumbnails/35.jpg)
Set up a TextView (including declaring and casting). Note the need to Import.
35
![Page 36: Android Hello World](https://reader035.fdocuments.us/reader035/viewer/2022062314/5681394e550346895da0e9ce/html5/thumbnails/36.jpg)
Add line to change the text
36
![Page 37: Android Hello World](https://reader035.fdocuments.us/reader035/viewer/2022062314/5681394e550346895da0e9ce/html5/thumbnails/37.jpg)
Sometimes the project does not seem to open up right away. Drag the lock, click OK, expand the menu
37
![Page 38: Android Hello World](https://reader035.fdocuments.us/reader035/viewer/2022062314/5681394e550346895da0e9ce/html5/thumbnails/38.jpg)
Click OK. Click on project icon.
38
![Page 39: Android Hello World](https://reader035.fdocuments.us/reader035/viewer/2022062314/5681394e550346895da0e9ce/html5/thumbnails/39.jpg)
Before and after the click
39