Learning the Language

Learning the Language

Android apps are typically written in a programming language called Java. In this stage we'll introduce you to Java and some of the basic concepts of programming like variables, arrays, and "if" statements. We'll also touch on some of the key principles of object-oriented development.

Extra Credit

Change the background color when the button is tapped

Add an ID to the RelativeLayout element in activity_main.xml. Then you can use that ID to get a RelativeLayout object just like we get a TextView and Button. The RelativeLayout object has a method called setBackgroundColor() that takes an int color code as a parameter. Use a color code from the Color class, i.e. Color.GREEN, and call this method when the button is clicked.

Change the background color conditionally

Add "if" statements to check the value of the answer in the onClick() method. You can compare it to the values stored in the mAnswers array of the CrystalBall object using the String.equals() method.

For example, answer.equals(crystalBall.mItems[0]) checks whether the answer equals the first item in the array or not. Change the background color for certain answers or certain types of answers, like make it red for negative answers and green for positive answers.