The View Class

The key element when writing an Android app is to design the User Interface (UI) because almost all interactions with Android devices take place through the user interface. Therefore we need to first learn about the UI, in particular, the Android’s View class before we can build Android Apps.

In Android, View class is the superclass of all UI components in Android. Most commonly used View subclasses include TextViews, EditTexts and Buttons. Simply put, every item on the user interface is a subclass of the Android’s View class.

A View object occupies a rectangular area on the screen and is responsible for the drawing and event handlingDrawing involves taking care of what is drawn within a view such as color and size. Events handling involves responding to events that occur within the view such as touch events or click events.

UI Components
These are specialized subclasses of View Class that act as controls or used to display, text, images, or video content on your phone. Android provides a set of standard views such as Button, CheckBox, ProgressBar and TextView, Radio Button, EditText, ImageViewButton and ImageView as illustrated below.


You can add views either from code or through XML layout files.  Most coders and that includes me use the layout option as you will do less coding.

XML stands for Extensible Markup Language. XML is a markup language much like HTML used to describe data. Xml itself is well readable both by human and machine. In Android we use xml for designing our layouts because xml is lightweight language so it doesn’t make our layout heavy.

Views may have an integer id associated with them. These ids are typically assigned in the layout XML files, and are used to find specific views within the view tree. For instance, you can define a button in the layout file and assign it a unique id and then use this id to identify it in the source code as shown on the below code excerpts.

[cc lang=”xml”]

One thought on “The View Class

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.