Friday, June 7, 2013

Android 1: Lesson 5

Android 1: Lesson 5



Lesson 5: Expanding on Java for Counter App
INTRODUCTION
In this lesson you will be expanding your Java knowledge, and actually assigning the Java code to the XML layout. Making the app actually alter itself and work like a normal application.


LESSON OBJECTIVES
By the end of this lesson, you will be able to:
1. Importing more pieces of Java
2. Setting the intent of the Java
3. Setting the starting number for the counter
LEARNING SEQUENCE


Required Reading
Read the following:
Introduction To Development Environment
·        Eclipse
·        Android
·        Considerations for beginning programming.
Resources
View the following:
1.      Eclipse
2.      Android Development
Assignments
  1. In this lesson, we’ll start with the your ‘MainActivity.java’ file, and be editing the app solely in java
  2. First you’ll want to import a few more pieces of java to complete the app.
  3. Move your cursor until you are under the ‘android.view.menu’ and type out ‘import android.view.View;’. Make sure that View is capitalized. This is importing the setContentView in the app, letting it view the R.layout.activity_main’ file. Which is your XML file
  4. then you’ll want to type out ‘import android.widget.Button;’ and ‘import android.widget.TextView;’ These both allow you to edit and change the Button and TextView in the java, obviously.
  5. Like HTML coding, and all other coding, you’ll want to make sure you end the code by typing ; at the end each piece of code
  6. Next we’ll be adding the intent. Move your cursor to after the ‘Activity {‘ so that it is located within the activity. hit ‘ENTER’. You can locate it where I have mine, but it doesn’t matter that much. I hit enter twice, then indent. just for convenience
  7. Now type out ‘int counter;’ the color of the code should change to the same we have in our video. This is setting the intent of the app to being a counter, which is a preset word in Java.  
  8. Hit enter again, and type of ‘Button add, sub;’. This is creating the Java for both buttons, one being an adding button, the other being subtraction.
  9. Hit enter again, and type ‘TextView display;’. This piece of code makes the Java for TextView, allowing it to be altered and changed.
  10. Now that that’s done. Move your cursor again past the ‘protect void’, until you pass the ‘(R.layout.activity_main);’. Hit enter again, and type ‘counter = x;’ Where x is, type whatever number you want to change what the starting number is for the counter. Mine is 0, yours can be any number you want.