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.
5 videos • 3 quizzes • 2 code challenges
-
Play
Watch
Comments and Empty Strings
3 minutes 53 seconds
-
ABC
Preview
Quiz: Comments and Empty Strings
5 questions
-
Play
Preview
Objects and Random Numbers
6 minutes 11 seconds
-
Code Challenge
Preview
Code Challenge: Objects and Random Numbers
4 objectives
-
Play
Preview
Conditionals: Writing an if statement
8 minutes 24 seconds
-
ABC
Preview
Quiz: Conditionals: Writing an if Statement
5 questions
-
Play
Preview
Introduction to Arrays
7 minutes 1 seconds
-
Code Challenge
Preview
Code Challenge: Introduction to Arrays
4 objectives
-
Play
Preview
Simple Refactoring
10 minutes 44 seconds
-
ABC
Preview
Quiz: Simple Refactoring
5 questions
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.