|
| 1 | +# First Tutorial |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +The first meeting tutorial, building your first Android app! |
| 6 | + |
| 7 | + |
| 8 | +#Step 1 |
| 9 | + |
| 10 | +Installing Android Studio |
| 11 | + |
| 12 | +Go to http://developer.android.com/sdk/index.html and download Android Studio. Install it. Make sure you have the JDK |
| 13 | +installed on your computer: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html |
| 14 | + |
| 15 | +#Step 2 |
| 16 | +Creating a new Project |
| 17 | + |
| 18 | +Open up Android Studio and Start a new Project... |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | +Name your application (MyFirstApp, etc.), and set the Minimum SDK |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | +Start with a Blank Activity, name it MainActivity. |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | +Gradle should invocate your project, and take you into the activity! |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | +#Step 2 |
| 37 | +Adding Content |
| 38 | + |
| 39 | + |
| 40 | +Go to your activity_main.xml. the XML specs the appearance of the file, while the Java activities add functionality. |
| 41 | +Drag a Button (under Widgets) onto the screen. |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | +If you go to the Text tab in the XML, you'll be able to see the code generated by Android Studio for the Button. |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | +Run your code if you wish, and you'll see the new Button next to your Hello World! |
| 50 | + |
| 51 | +Now that we have a button, let's make it do something. |
| 52 | + |
| 53 | + |
| 54 | +#Step 3 |
| 55 | +Adding functionality to your content |
| 56 | + |
| 57 | + |
| 58 | +Let's define a method in our MainActivity called buttonOnClick, which will execute an action when the Button is clicked. |
| 59 | + |
| 60 | + |
| 61 | + |
| 62 | +In this method, lets make a TextView variable that will change the Text displayed when the button is clicked. |
| 63 | +You can do this by first linking a TextView variable to the one being displayed, and then updating it. |
| 64 | +It will update when the method is called. |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | +Let's add a couple things to our XML to support the actions: |
| 69 | +If it isn't already there, add the line: |
| 70 | +``` |
| 71 | +android:id="@+id/textView" |
| 72 | +``` |
| 73 | +inside your TextView so that the buttonOnClick function can access and change the View. |
| 74 | +Additionally, add the following line: |
| 75 | +``` |
| 76 | +android:onClick="buttonOnClick" |
| 77 | +``` |
| 78 | +to your Button. This has your program execute the specified method when the button is clicked. |
| 79 | + |
| 80 | + |
| 81 | + |
| 82 | + |
| 83 | +#Step 4 |
| 84 | + |
| 85 | +Run your app! |
| 86 | + |
| 87 | + |
| 88 | +Click the button! |
| 89 | + |
| 90 | + |
| 91 | + |
| 92 | + |
| 93 | +If you enjoyed this tutorial and want to learn more, check out the rest of the tutorials on this Github and come to SiGMobile |
| 94 | +meetings! We'll see you there! |
| 95 | + |
| 96 | + |
0 commit comments