This course will be retired on July 14, 2025.
Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
- Accessing Views in Code: Declaring Variables 5:20
- Accessing Views in Code: Assigning Variables 6:24
- Initializing a Button 1 objective
- Making a Button Do Something 4:35
- Adding the OnClick Method 2:36
- Android Programming Basics 5 questions
- Generating a Random Number 4:08
- Choosing a Random Fact 4:52
- Using the Random Class 4 objectives
Well done!
You have completed Build a Simple Android App with Java!

- 2x 2x
- 1.75x 1.75x
- 1.5x 1.5x
- 1.25x 1.25x
- 1.1x 1.1x
- 1x 1x
- 0.75x 0.75x
- 0.5x 0.5x
Now that we've declared our variables, it's time to start using them! In this video we'll see how we can assign these variables to the corresponded Views from our layout.
Read Me!
Android recently updated the findViewById
method to be generic. This means, in most cases, that a cast (e.g. (Button)
) is no longer necessary. If you don't see an error when using findViewById
, that just means you're on a newer version of Android than I am :)
Related Links
- Android Style Guidelines
- A Note on Casting - (scroll down a bit)
Documentation
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up-
Eric Cho
2,151 Points0 Answers
-
Eric Cho
2,151 Points1 Answer
-
Hazel Pan
3,510 PointsI can not find the r class/folder under the source folder
Posted by Hazel PanHazel Pan
3,510 Points2 Answers
-
Malcolm Taylor
496 PointsI didn't understand where you put the code for classes and why? Video just skips to blank screen without any context.
Posted by Malcolm TaylorMalcolm Taylor
496 Points1 Answer
-
Ranvir Sahota
9,844 PointsWhy is res class a requirment to use findViewByID?
Posted by Ranvir SahotaRanvir Sahota
9,844 Points0 Answers
-
PLUS
Nadav Kern
Courses Plus Student 1,155 Points2 Answers
-
Riya Prasannan
806 PointsNot able to assign values to factTextView. factTextview2 shows correct though, but dont have the variable factTextView2.
Posted by Riya PrasannanRiya Prasannan
806 Points4 Answers
-
Yoshi Gomez
377 Points1 Answer
-
MOD
Jason Anders
Treehouse Moderator 145,860 Points0 Answers
View all discussions for this video
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up