Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialWalter Bueso
10,654 PointsNot fully grasping what "Views" are.
I understand that casting specifies the type of "View" that findViewById returns, but I'm not fully comprehending what a "View" is. Can someone explain it to me? Thank you.
2 Answers
Seth Kroger
56,413 PointsA "View" in the general sense is what something looks like. In Android a View describes an area of the display/screen and what should be shown there (and in some cases, how to respond to user input). There are different kinds of Views, all descended from the View class, depending on what needs to be done. It could be in image, text label, button, etc. You can have interactive views like an input field. You can also have Views inside other views, so you can specify the layout of a group of buttons, a text caption below an image, etc.
Daniel Hartin
18,106 PointsHi Walter
Every element you place inside your XML file is a View. Because of a technique called inheritance every element (Button, EditText, TextView etc.etc.) extend the original code from the View class and supercede this to make a new class with unique methods while still retaining all the old methods that are common across all views.
for example you create a class called Cat which has methods and variables common to every cat like eat, sleep, drink etc etc. You could then create new classes that extend the cat class such as Lion, Tiger and HouseCat which adopt new methods such as Roar which are not applicable to cat as they are unique to the Lion but methods such as Eat, Sleep and Drink would still be available as they would be used by all cats (strange example but one I was told once upon a time which does kind of work).
So basically View holds methods that are common across all views regardless of type things such as position and size will have to be defined in all views, while button will still need a size and position it will also create new methods such as onClick which extend the View class further to make a more 'defined View' which you know as Button.
android's documentation on Views is here - http://developer.android.com/reference/android/view/View.html
Hopefully this makes sense Daniel