Module 8: Android UI Controls: Gordon College
Module 8: Android UI Controls: Gordon College
Module 8: Android UI Controls: Gordon College
City of Olongapo
-o0o-
GORDON COLLEGE
Olongapo City Sports Complex, Donor St., East Tapinac, Olongapo City 2200
www.gordoncollege.edu.ph
Module 8 will focus on the basic UI Controls that you can utilize in creating your
simple Android Mobile App and how the events can be implemented on some of
these controls.
IT Elective II (Lec) NOT FOR SALE, Exclusive for Gordon College Only!
Neil Marc R. Biron, Instructor (1st Semester, AY 2020-2021) | 1 of 11
Republic of the Philippines
City of Olongapo
-o0o-
GORDON COLLEGE
Olongapo City Sports Complex, Donor St., East Tapinac, Olongapo City 2200
www.gordoncollege.edu.ph
The View is a base class for all UI components in android and it is used to create
interactive UI components such as TextView, EditText, Checkbox, Radio Button,
etc. and it is responsible for event handling and drawing.
The ViewGroup is a subclass of View and it will act as a base class for layouts
and layout parameters. The ViewGroup will provide invisible containers to hold
other Views or ViewGroups and to define the layout properties.
The android framework will allow us to use either or both of these methods to
define our application’s UI.
Following are the some of common View subclasses that will be used in android
applications.
• TextView
• EditText
• Button
• CheckBox
• RadioButton
• ImageButton
• Progress Bar
• Spinner
There are so many other Views that you can utilize in android.
ViewGroup - The ViewGroup is a subclass of View and it will act as a base class
for layouts and layouts parameters. The ViewGroup will provide an invisible
containers to hold other Views or ViewGroups and to define the layout
properties.
For example, Linear Layout is the ViewGroup that contains a UI controls like
button, textview, etc. and other layouts also.
• Linear Layout
• Relative Layout
• Table Layout
IT Elective II (Lec) NOT FOR SALE, Exclusive for Gordon College Only!
Neil Marc R. Biron, Instructor (1st Semester, AY 2020-2021) | 2 of 11
Republic of the Philippines
City of Olongapo
-o0o-
GORDON COLLEGE
Olongapo City Sports Complex, Donor St., East Tapinac, Olongapo City 2200
www.gordoncollege.edu.ph
• Frame Layout
• Web View
• List View
• Grid View
Both View and ViewGroup subclasses together will play a key role to create a
layouts in android applications.
1 TextView
IT Elective II (Lec) NOT FOR SALE, Exclusive for Gordon College Only!
Neil Marc R. Biron, Instructor (1st Semester, AY 2020-2021) | 3 of 11
Republic of the Philippines
City of Olongapo
-o0o-
GORDON COLLEGE
Olongapo City Sports Complex, Donor St., East Tapinac, Olongapo City 2200
www.gordoncollege.edu.ph
A drop-down list that allows users to select one value from a set.
12 TimePicker
The TimePicker view enables users to select a time of the day, in either 24-hour mode or
AM/PM mode.
13 DatePicker
The DatePicker view enables users to select a date of the day.
IT Elective II (Lec) NOT FOR SALE, Exclusive for Gordon College Only!
Neil Marc R. Biron, Instructor (1st Semester, AY 2020-2021) | 4 of 11
Republic of the Philippines
City of Olongapo
-o0o-
GORDON COLLEGE
Olongapo City Sports Complex, Donor St., East Tapinac, Olongapo City 2200
www.gordoncollege.edu.ph
In android, each input control is having a specific set of events and these events
will be raised when the user performs particular action like, entering the text or
touches the button.
Remember that we need to create a user interface (UI) layout files in /res/layout
project directory, then only the layout files will compile properly.
If you observe above code we are calling our layout using setContentView
method in the form of R.layout.layout_file_name. Here our xml file name is
activity_main.xml so we used file name activity_main.
Generally, during the launch of our activity, onCreate() callback method will be
called by android framework to get the required layout for an activity.
IT Elective II (Lec) NOT FOR SALE, Exclusive for Gordon College Only!
Neil Marc R. Biron, Instructor (1st Semester, AY 2020-2021) | 5 of 11
Republic of the Philippines
City of Olongapo
-o0o-
GORDON COLLEGE
Olongapo City Sports Complex, Donor St., East Tapinac, Olongapo City 2200
www.gordoncollege.edu.ph
Following is the example of setting width and height for View and ViewGroup
elements in the XML layout file.
If you observe above example, we used different values to set layout_width and
layout_height, those are
• match_parent
• wrap_content
If we set value match_parent, then the View or ViewGroup will try to match
with parent width or height.
If we set value wrap_content, then the View or ViewGroup will try to adjust its
width or height based on the content.
IT Elective II (Lec) NOT FOR SALE, Exclusive for Gordon College Only!
Neil Marc R. Biron, Instructor (1st Semester, AY 2020-2021) | 6 of 11
Republic of the Philippines
City of Olongapo
-o0o-
GORDON COLLEGE
Olongapo City Sports Complex, Donor St., East Tapinac, Olongapo City 2200
www.gordoncollege.edu.ph
Included in the event listener interfaces are the following callback methods:
These methods are the sole inhabitants of their respective interface. To define
one of these methods and handle your events, implement the nested interface in
your Activity or define it as an anonymous class. Then, pass an instance of your
implementation to the respective View.set...Listener() method. (E.g., call
setOnClickListener() and pass it your implementation of the OnClickListener.)
IT Elective II (Lec) NOT FOR SALE, Exclusive for Gordon College Only!
Neil Marc R. Biron, Instructor (1st Semester, AY 2020-2021) | 7 of 11
Republic of the Philippines
City of Olongapo
-o0o-
GORDON COLLEGE
Olongapo City Sports Complex, Donor St., East Tapinac, Olongapo City 2200
www.gordoncollege.edu.ph
The example below shows how to register an on-click listener for a Button;
IT Elective II (Lec) NOT FOR SALE, Exclusive for Gordon College Only!
Neil Marc R. Biron, Instructor (1st Semester, AY 2020-2021) | 8 of 11
Republic of the Philippines
City of Olongapo
-o0o-
GORDON COLLEGE
Olongapo City Sports Complex, Donor St., East Tapinac, Olongapo City 2200
www.gordoncollege.edu.ph
IT Elective II (Lec) NOT FOR SALE, Exclusive for Gordon College Only!
Neil Marc R. Biron, Instructor (1st Semester, AY 2020-2021) | 9 of 11
Republic of the Philippines
City of Olongapo
-o0o-
GORDON COLLEGE
Olongapo City Sports Complex, Donor St., East Tapinac, Olongapo City 2200
www.gordoncollege.edu.ph
V. LEARNING TASK
Holistic Rubric
Exceeding Meeting Approaching Below None
(10) (8) (6) (2) (0)
Substantial,
Content Clarity
specific, and/or
The presence of ideas Sufficient
illustrative
developed through developed Limited content Superficial
content No content
facts, examples, content with with inadequate and/or
demonstrating or answer
illustrations, details, adequate elaboration or minimal
strong provided.
opinions, statistics, elaboration or explanation content
development and
reasons, and/or explanation.
sophisticated
explanations.
ideas.
1. Aside from the discussed common UI controls, what other controls do you
think should a new developer need to familiarize? Why?
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
2. Give two important events that can implement in a Spinner. How can we
register these events?
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
Score Sheet
Question 1 Question 2 Question 3 Total Score
IT Elective II (Lec) NOT FOR SALE, Exclusive for Gordon College Only!
Neil Marc R. Biron, Instructor (1st Semester, AY 2020-2021) | 10 of 11
Republic of the Philippines
City of Olongapo
-o0o-
GORDON COLLEGE
Olongapo City Sports Complex, Donor St., East Tapinac, Olongapo City 2200
www.gordoncollege.edu.ph
VI. REFERENCES
Online Resources
• https://www.tutlane.com/tutorial/android/android-input-events-event-
listeners-event-handling
• https://www.tutlane.com/tutorial/android/android-ui-controls-textview-
edittext-radio-button-checkbox
• https://www.tutlane.com/tutorial/android/android-view-and-viewgroup-
with-examples
• https://www.tutorialspoint.com/android/android_user_interface_controls.ht
m
IT Elective II (Lec) NOT FOR SALE, Exclusive for Gordon College Only!
Neil Marc R. Biron, Instructor (1st Semester, AY 2020-2021) | 11 of 11