Download as pdf or txt
Download as pdf or txt
You are on page 1of 144

Module 1

Introduction to Android
OBJECTIVES

At the end of the chapter, the learner should be able to:


• To discuss how Android started
• To recognize the number of Android users in the market
• To differentiate Android versions
• To describe Android features
• To understand Android architecture
What is Android?
• Mobile operating system based on Linux
• Originally developed by Android Inc.
• Google purchased Android Inc. in 2005
• Android OS is open and free

https://www.tutorialspoint.com/android/android_overview.htm
Source: https://gs.statcounter.com/os-market-
share/mobile/worldwide/#monthly-201706-202308-bar
Android
Versions
and their names

Source: https://mfidie.com/list-of-all-android-versions-and-their-names/
• Both versions are first commercial
versions. Officially released publicly in
2008 and 2009. The first android
commercial version was placed on HTC
Android 1.0 and dream device. These versions were
released without codename.
• Android 1.0 (alpha):
1.1 (Unnamed) • Google Maps
• Camera
• Gmail, Contacts and Google
Synchronization
• Web Browser
• Wireless supports – WiFi and
Bluetooth
• Android 1.1 (beta):
• Add Save attachment in message
• Provides reviews and details when
user search business on maps
Released in April 2009. The
first released codename
with official name. It
brought features in UI
Android 1.5 design and update several
(CupCake) new features are:

• New upload service on


YouTube and Picasa like
Uploading Videos and
Photos.
• Supporting in MPEG-4,
Video recording
• Improving Web Browser-
Copy and Paste facility
Released in Sept
2009. It Including
various features
Android 1.6
(Donut) • It supports large
screen size
• Providing Gallery
and Camera
features.
• Improve speed in
system apps
Released in Oct 2009
and 2.1 version released
in Dec 2009. There
Android 2.0 and features :
2.1 (Eclair)
• Update UI
• Support Live
Wallpaper
• Support Bluetooth
2.1
• Improve Google map
• Minor API Changes
Released in May 2010.
There features :
Android 2.2 • Support Animated GIF
(Froyo) • WiFi Support Hotspot
functionality
• Speed improvements
• Upload file support in
browser
• Support numeric and
alphanumeric
password
Released in December 2010.
Android 2.3 and It was officially announced
in Nexus S android phone
2.4 which is Google co-
developed with Samsung.
(Gingerbread)
▪ Improve Copy-Paste
Facility
▪ Updated UI design
▪ Social Networking
Supports
▪ Easy use of keyboard
Android 3.0 was released in
February 2011 quickly
Android 3.0, 3.1 followed by 3.1 and 3.2 in
July and August, 2011.
and 3.2 ▪ Gmail App improvements
(Honeycomb) ▪ Updated 3D UI
▪ Media Sync from SD Card
▪ Google eBooks
▪ Google Talk Video Chat
▪ Support Adobe Flash in
Browser
▪ High-performance WiFi
Connections and Lock
▪ Chinese handwriting
Released in October 2011. It
was Google’s attempt
synthesize Honeycomb.
Android 4.0
▪ Improved text input and
(Ice-Cream spelling check
▪ WiFi direct
Sandwich) ▪ Photo Decor facility
▪ Improve in keyboard
correction
▪ Face Lock
▪ Improve in video recording
resolution
▪ Camera performance
▪ Up to 16 tabs in web
browser
Released in July 2012. ‘Google now’
is the main feature.

Android 4.1, 4.2 ▪



Voice search
Smooth UI
and 4.3 (Jelly ▪

Improve camera application
Security enhancement
Bean) ▪

Voice typing
Multiple user accounts on tablet
only
▪ 4k resolution support
▪ Supporting Bluetooth Low Energy
▪ Bi-directional text and other
language support
▪ Support USB audio
▪ Lock screen improvement
▪ Set the volume of incoming calls
and showing message alert
▪ Native emoji support
Released in September 2013.

▪ Screen Recording
Android 4.4 ▪ KitKat adds a feature in
‘Google now’. Its name is
(Kikat) ‘OK Google’. “OK Google”
allows access google now to
the user without touching
your mobile phone.
▪ GPS Support
▪ Offline music support
▪ UI updates for google map
navigation and alarm.
▪ Also, introduce Emoji’ to
google keyboard.
Released in November
2014. Support ART(
Android RunTime)
Android 5.0 and
5.1 (Lollipop) ▪ Save battery on some
device
▪ Improvement in UI
▪ New material design
▪ Bug fixes
▪ Multiple sim card
support
▪ High definition voice
call
Released in May 2015.

▪ Fingerprint
Android 6.0 authentication
(Marshmallow) ▪ USB Type C support
▪ Save battery-’Sleep
Mode’
▪ App permission
model-OPT(send
request for
permission)
▪ New Emoji’s
Released in August
2016. It was announced
with native split-screen
Android 7.0 mode and data saver
(Nougat) feature.

▪ Provide multitasking
▪ Providing multi-
window mode
▪ Improve in storage
manager
▪ Display touch
improvement
Released in August 2017.
There some updated new
Android 8.0 features
(Oreo)
▪ Support PIP(Picture-in-
Picture)
▪ Multi-display support
▪ Google Play support
▪ Adaptive icons
▪ Improve notification
system
Released in August 2018.

▪ A "screenshot" button
Android 9.0 has been added
▪ A new "Lockdown"
(Pie) mode for biometrics
▪ Support for display
cutouts
▪ Adaptive Batter
prediction
▪ Adaptive brightness
modifies screen
brightness based on
user habits.
Android 10
Released in September 3 2019. Known as “Queen
Cake”, internally as Quince Tart.

▪ New permissions to access location in


background and to access photo, video and
audio files
▪ Sharing shortcuts, which allow sharing content
with a contact directly
▪ Dynamic depth format for photos, which allow
changing background blur after taking a photo
▪ New system-wide dark theme/mode
Android 11
Released in September 8, 2020. Known as
“Red Velvet Cake”
Android 12
Released in October 4, 2021. Known as
“Snow Cone”
Android 13
Released in August 15, 2022. Known as
“Tiramisu”
Android 14 Android 15
“Upside Down Cake “Vanilla Ice Cream”
Android Features
Android Architecture
A software stack of components to support a mobile device
needs. Android software stack contains a Linux Kernel,
collection of c/c++ libraries which is exposed through an
application framework services, runtime and application.

1. Applications
2. Android Framework
3. Android Runtime
4. Platform Libraries
5. Linux Kernel
Source: https://www.tutlane.com/tutorial/android/android-architecture
Android
Architecture

Source: https://www.tutlane.com/tutorial/android/android-architecture
Android Architecture
Linux Kernel is the main component in android to provide
its operating system functions to mobile and Dalvik Virutal
Machine (DVM) which is responsible for running a mobile
application.

Source: https://www.tutlane.com/tutorial/android/android-architecture
References
• https://google-developer-training.gitbooks.io/android-developer-fundamentals-course-
concepts/content/en/Unit%201/10_c_intro_to_android.html

• https://www.tutorialspoint.com/android/android_overview.htm

• https://www.udemy.com/learn-android-application-development-y/learn/lecture/7782698#overview

• https://www.androidauthority.com/history-android-os-name-789433/

• https://developer.android.com/about/versions

• https://mfidie.com/list-of-all-android-versions-and-their-names/#android-14
Module 2
Android Studio
OBJECTIVES

At the end of the chapter, the learner should be able to:


• To identify prerequisites on Android Studio installation
• To identify system requirements
• To create an Android project
• To familiarize with Android Studio Interface
• To run the first Android application
Prerequisites

• JDK
https://www.oracle.com/technetwork/java/javase/downloads/index.html

• Android Studio
https://developer.android.com/studio/
System Requirements

https://developer.android.com/studio
Create an Android project
1. click Start a new Android Studio project Or if you have a project opened, select File > New > New
Project.
Create an Android project
2. In the Choose your project window, select Empty Activity
3. Click Next.
4. In the Configure your project window, enter the following values:
Name: "My First App"
Package name: "com.example.myfirstapp"
Check the box next to Use AndroidX artifacts
You might want to change the project location.
Leave the other options as they are.
5. If you prefer to write your app in Java, select Java from the Language drop down.
6. Click Finish.
Java or
Kotlin
Android Studio Interface
Android Studio Interface
1. The toolbar lets you carry out a wide range of actions, including running your app and
launching Android tools.
2. The navigation bar helps you navigate through your project and open files for editing. It
provides a more compact view of the structure visible in the Project window.
3. The editor window is where you create and modify code. Depending on the current file
type, the editor can change. For example, when viewing a layout file, the editor displays
the Layout Editor.
4. The tool window bar runs around the outside of the IDE window and contains the buttons
that allow you to expand or collapse individual tool windows.
5. The tool windows give you access to specific tasks like project management, search,
version control, and more. You can expand them and collapse them.
6. The status bar displays the status of your project and the IDE itself, as well as any
warnings or messages.
Running your Application
• Run on real Device
• Run on Emulator
Running your Application
• Run on real Device
o Connect your Android Phone to the computer

o Make sure USB Debugging is enabled (you can


do this by enabling Developer options first)
Running your Application
• Run on Emulator
o Navigate to Device Manager
and select Create Device
o Select your screen size and kind
of phone
o Select Android SDK version
DEMONSTRATION

IDE Familiarization
References
• https://developer.android.com/training/basics/firstapp/creating-project

• https://developer.android.com/studio/intro/?gclid=EAIaIQobChMIxuSkvaqk4wIVUnZgCh131Qe3EA
AYASABEgJSz_D_BwE
Module 3
Application Components and
Resources
OBJECTIVES

At the end of the chapter, the learner should be able to:


• To understand Android application components
• To identify the use of each component
• To describe additional components
• To identify the different Android resources
• To access resources in Code and XML
Module 3
Application Components and
Resources
What is Application Components?
Application components are the essential building
blocks of an Android application. These components
are loosely coupled by the application manifest
file AndroidManifest.xml that describes each
component of the application and how they interact.
Components & Description
Activities
1 They dictate the UI and handle the user interaction to the smart
phone screen.
Services
2 They handle background processing associated with an
application.
Broadcast Receivers
3 They handle communication between Android OS and
applications.
Content Providers
4 They handle data and database management issues.
https://developer.android.com/studio
Activities
An activity represents a single screen with a user interface,
in-short Activity performs actions on the screen. For example,
an email application might have one activity that shows a list
of new emails, another activity to compose an email, and
another activity for reading emails. If an application has more
than one activity, then one of them should be marked as the
activity that is presented when the application is launched.

An activity is implemented as a subclass of Activity class as follows −


Services
A service is a component that runs in the background to
perform long-running operations. For example, a service
might play music in the background while the user is in a
different application, or it might fetch data over the network
without blocking user interaction with an activity.

A service is implemented as a subclass of Service class as


follows −
Broadcast Receivers
Broadcast Receivers simply respond to broadcast messages from
other applications or from the system. For example, applications
can also initiate broadcasts to let other applications know that some
data has been downloaded to the device and is available for them
to use, so this is broadcast receiver who will intercept this
communication and will initiate appropriate action.

A broadcast receiver is implemented as a subclass of


BroadcastReceiver class and each message is broadcaster as an
Intent object.
Content Providers
A content provider component supplies data from one
application to others on request. Such requests are handled
by the methods of the ContentResolver class. The data may
be stored in the file system, the database or somewhere else
entirely.

A content provider is implemented as a subclass of


ContentProvider class and must implement a standard set of
APIs that enable other applications to perform transactions.
Additional Components
# Components & Description
1 Fragments
Represents a portion of user interface in an Activity.
2 Views
UI elements that are drawn on-screen including buttons, lists forms etc.
3 Layouts
View hierarchies that control screen format and appearance of the views.
4 Intents
Messages wiring components together.
5 Resources
External elements, such as strings, constants and drawable pictures.
6 Manifest
Configuration file for the application.
Module 3
Application Components and
Resources
Android Resources
Resources are the additional files
and static content that your code
uses, such as bitmaps, layout
definitions, user interface strings,
animation instructions, and more.

These resources are always maintained


separately in various sub-directories
under res/ directory of the project.
Resource Organization
# Directory & Resource Type
1 animator/
XML files that define Property animations.

2 anim/
XML files that define property animations. They are saved in res/anim/ folder and accessed from
the R.anim class.

XML files that define Tween animations. Property animations can also be saved in this directory, but
the animator/ directory is preferred for property animations to distinguish between the two types.
3 color/
XML files that define a state list of colors. They are saved in res/color/ and accessed from
the R.color class.

XML files that define a state list of colors. For more information, see Color state list resource.
Resource Organization
# Directory & Resource Type
4 drawable/
Image files like .png, .jpg, .gif or XML files that are compiled into bitmaps, state lists, shapes,
animation drawable. They are saved in res/drawable/ and accessed from the R.drawable class.

Bitmap files (PNG, .9.png, JPG, or GIF) or XML files that are compiled into the following drawable
resource subtypes:
• Bitmap files
• Nine-patches (re-sizable bitmaps)
• State lists
• Shapes
• Animation drawables
• Other drawables
For more information, see Drawable resources.
5 layout/
XML files that define a user interface layout. They are saved in res/layout/ and accessed from
the R.layout class.

XML files that define a user interface layout. For more information, see Layout resource.
Resource Organization
# Directory & Resource Type
6 menu/
XML files that define application menus, such as an Options Menu, Context Menu, or Sub Menu.
They are saved in res/menu/ and accessed from the R.menu class.

XML files that define app menus, such as an options menu, context menu, or submenu. For more
information, see Menu resource.
7 raw/
Arbitrary files to save in their raw form. You need to call Resources.openRawResource() with the
resource ID, which is R.raw.filename to open such raw files.

Arbitrary files to save in their raw form. To open these resources with a raw InputStream,
call Resources.openRawResource() with the resource ID, which is R.raw.filename.
However, if you need access to the original filenames and file hierarchy, consider saving resources
in the assets/ directory instead of res/raw/. Files in assets/ aren't given a resource ID, so you can
only read them using AssetManager.
Resource Organization
# Directory & Resource Type
8 values/
XML files that contain simple values, such as strings, integers, and colors.

Whereas XML resource files in other res/ subdirectories define a single resource based on the XML
filename, files in the values/ directory describe multiple resources. For a file in this directory, each
child of the <resources> element defines a single resource. For example, a <string> element creates
an R.string resource, and a <color> element creates an R.color resource.

Because each resource is defined with its own XML element, you can name the file whatever you
want and place different resource types in one file. However, for clarity, you might want to place
unique resource types in different files. For example, here are some filename conventions for
resources you can create in this directory:
• arrays.xml for resource arrays (Typed arrays)
• colors.xml for Color values
• dimens.xml for Dimension values
• strings.xml for String values
• styles.xml for Styles
For more information, see String resources, Style resource, and More resource types.
Resource Organization
# Directory & Resource Type
9 xml/
Arbitrary XML files that can be read at runtime by calling Resources.getXML(). Various XML
configuration files must be saved here, such as a Search configuration.
10 font/
Font files with extensions such as TTF, OTF, or TTC, or XML files that include a <font-
family> element. For more information about fonts as resources, see Add a font as an XML
resource.
Accessing Resources
• Accessing Resources in Code
When your Android application is compiled, a R class gets
generated, which contains resource IDs for all the resources
available in your res/ directory. You can use R class to
access that resource using sub-directory and resource name
or directly resource ID.
Accessing Resources
• Accessing Resources in Code
Example 1
To access res/drawable/myimage.png and set an ImageView you will use following code −
Accessing Resources
• Accessing Resources in Code
Example 2
Consider next example where res/values/strings.xml has following definition −

you can set the text on a TextView object with ID msg using a resource ID as follows −
Accessing Resources
• Accessing Resources in Code
Example 3
Consider a layout
res/layout/activity_main.xml
with the following
definition −
Accessing Resources
• Accessing Resources in Code
Example 3
This application code will load this layout for an Activity, in the onCreate() method as follows −
Accessing Resources
• Accessing Resources in XML
Consider the following resource XML res/values/strings.xml file that includes a color resource
and a string resource −

Now you can use these resources in the following layout file to set the text color and text string
as follows −
DEMONSTRATION

Components and Resources


References
• https://www.tutorialspoint.com/android/android_application_components.htm

• https://developer.android.com/guide/topics/resources/providing-resources
Module 4
Activities
OBJECTIVES

At the end of the chapter, the learner should be able to:


• To describe what activities are
• To understand the activity life cycle
• To identify the different methods associated in activity life
cycle
• To create an activity
Activities
An Android activity is one screen of the Android app's user
interface. In that way an Android activity is very similar to
windows in a desktop application. An Android app may
contain one or more activities, meaning one or more screens.
The Android app starts by showing the main activity, and
from there the app may make it possible to open additional
activities.
Activity Life Cycle
Any Android activity goes through
a certain life cycle during its life
inside the Android app.

http://tutorials.jenkov.com/android/activity.html
Activity Life Cycle Methods
All activities in your Android apps are represented by an activity class. These
activity classes are subclasses of android.app.Activity. The Activity class contains
a set of methods that corresponds to the life cycle states an activity can be in.

onCreate()
This is the first callback and called when the activity is first created.
onStart()
This callback is called when the activity becomes visible to the user.
onResume()
This is called when the user starts interacting with the application.

http://tutorials.jenkov.com/android/activity.html
Activity Life Cycle Methods
onPause()
The paused activity does not receive user input and cannot execute
any code and called when the current activity is being paused and
the previous activity is being resumed.
onStop()
This callback is called when the activity is no longer visible.
onDestroy()
This callback is called before the activity is destroyed by the system.
onRestart()
This callback is called when the activity restarts after stopping it.
http://tutorials.jenkov.com/android/activity.html
Creating an Activity
An activity is a subclass of the Android class android.app.Activity .

http://tutorials.jenkov.com/android/activity.html
Creating an Activity
All activities, should be documented on your manifest file. To do
this, add an <activity> element as a child of the <application>
element.

https://developer.android.com/guide/components/activities/intro-activities
Creating an Activity
An activity class loads all the UI component using the XML file available
in res/layout folder of the project during the onCreate() callback.
Following statement loads UI components from
res/layout/activity_main.xml file:

http://tutorials.jenkov.com/android/activity.html
DEMONSTRATION

Creating activity on Android


Studio
References
• https://www.tutorialspoint.com/android/android_acitivities.htm
Module 5
Android User Interface
OBJECTIVES

At the end of the chapter, the learner should be able to:


• To understand what is a view and a viewgroup
• To declare view and viewgroup in two different ways
• To design interface using multiple view and viewgroup
• To apply different event listeners
• To construct an application with view, viewgroup, and events
< Layouts >
Layouts
• Defines the structure for a user interface in your app, such as in an activity.
• All elements are built using a hierarchy of View and ViewGroup objects.
• View - usually draws something the user can see and interact with.
• ViewGroup - invisible container that defines the layout structure for View
and other ViewGroup objects

Figure 1. Illustration of a view hierarchy, which defines a UI layout

Source: https://developer.android.com/guide/topics/ui/declaring-layout
Layouts
• Each layout file must contain exactly one root element, which must
be a View or ViewGroup object.
• Once you've defined the root element, you can add additional layout
objects or widgets as child elements
• to gradually build a View hierarchy that defines your layout.

Source: https://developer.android.com/guide/topics/ui/declaring-layout
Layouts
• View objects are usually called "widgets" and can be one of many
subclasses, such as Button or TextView.
• ViewGroup objects are usually called "layouts" can be one of many
types that provide a different layout structure, such as LinearLayout
or ConstraintLayout .
• View and ViewGroup can be declared in two ways:
• Declare UI Elements in XML
• Instantiate Layout Elements at Runtime

Source: https://developer.android.com/guide/topics/ui/declaring-layout
Declare UI elements in XML
Create your layout in xml

Load the xml from Activity

Source: https://www.tutlane.com/tutorial/android/android-ui-layouts-linear-relative-frame-table-listview-gridview-webview
Instantiate Layout Elements at Runtime

Source: https://www.tutlane.com/tutorial/android/android-ui-layouts-linear-relative-frame-table-listview-gridview-webview
Layout Resource
A layout resource defines the architecture for the UI in an Activity or a component of a UI.

file location:
res/layout/filename.xml
The filename will be used as the resource ID.
compiled resource datatype:
Resource pointer to a View (or subclass) resource.
resource reference:
In Java: R.layout.filename
In XML: @[package:]layout/filename

Source: https://developer.android.com/guide/topics/resources/layout-resource.html
Layout Resource – syntax

Source: https://developer.android.com/guide/topics/resources/layout-resource.html
Layout Resource – elements
<ViewGroup>
• A container for other View elements.
LinearLayout, RelativeLayout, and FrameLayout.
• Do not assume that any derivation of ViewGroup will accept nested Views.
• Some ViewGroups are implementations of the AdapterView class, which
determines its children only from an Adapter.
• attributes
android:id
android:layout_height
android:layout_width

Source: https://developer.android.com/guide/topics/resources/layout-resource.html
Layout Resource – elements
<View>
• An individual UI component, generally referred to as a "widget". Different kinds
of View objects include TextView, Button, and CheckBox.
• attributes
android:id
android:layout_height
android:layout_width

More attributes are supported by the View base class, and many more are supported by each
implementation of View.

Source: https://developer.android.com/guide/topics/resources/layout-resource.html
Layout Resource – elements
android:id
Resource ID. A unique resource name for the element, which you can use to
obtain a reference to the View or ViewGroup from your application.

For ID value, use syntax form: "@+id/name".


The plus symbol, +, indicates that this is a new resource ID and the aapt tool will
create a new resource integer in the R.java class, if it doesn't already exist.

There many other ID resources that are offered by the Android framework.
When referencing an Android resource ID, android:id="@id/resource_id"
Source: https://developer.android.com/guide/topics/resources/layout-resource.html
Layout Resource – elements
android:layout_height and android:layout_width
Dimension or keyword. Required. The height and width for the group

The height and width value can be expressed using any of the dimension units
supported by Android (px, dp, sp, pt, in, mm) or

Source: https://developer.android.com/guide/topics/resources/layout-resource.html
Layout Resource – elements
Custom View elements
You can create your own custom View and ViewGroup elements and
apply them to your layout the same as a standard layout element. You
can also specify the attributes supported in the XML element. To learn
more, see the https://developer.android.com/guide/topics/ui/custom-
components.html

Source: https://developer.android.com/guide/topics/resources/layout-resource.html
Layout Resource – example
XML file saved at res/layout/main_activity.xml:

Source: https://developer.android.com/guide/topics/resources/layout-resource.html
Loading View
1. Define a view/widget in the layout file and assign it a unique ID:

2. Then create an instance of the view object and capture it from the
layout (typically in the onCreate() method)

Source: https://developer.android.com/guide/topics/resources/layout-resource.html
Layout Attributes
Some of common layout attributes used in android application.

Source:https://www.tutlane.com/tutorial/android/android-ui-layouts-linear-relative-frame-table-listview-gridview-webview
Layout Types
• Linear Layout
• Relative Layout
• Frame Layout
• Table Layout
• Web View
• List View
• Grid View
Source:https://www.tutlane.com/tutorial/android/android-ui-layouts-linear-relative-frame-table-listview-gridview-webview
Linear Layout
LinearLayout is a ViewGroup subclass which is used to render all child View instances one by one
either in Horizontaldirection or Vertical direction based on the orientation property.

In android, we can specify the linear layout orientation using android:orientation attribute.

Source: https://www.tutlane.com/tutorial/android/android-linearlayout-with-examples
Linear Layout

Source: https://www.tutlane.com/tutorial/android/android-linearlayout-with-examples
Linear Layout

Source: https://www.tutlane.com/tutorial/android/android-linearlayout-with-examples
Relative Layout
It is a ViewGroup which is used to specify the position of
child View instances relative to each other (Child A to the
left of Child B) or relative to the parent (Aligned to the
top of parent).

RelativeLayout is very useful to design user interface


because by using relative layout we can eliminate the
nested view groups and keep our layout hierarchy flat,
which improves performance of application.

Source: https://www.tutlane.com/tutorial/android/android-relativelayout-with-
examples
Relative Layout
Following are the some of most useful layout properties available to views in RelativeLayout.

Source: https://www.tutlane.com/tutorial/android/android-relativelayout-with-
examples
Relative Layout

Source: https://www.tutlane.com/tutorial/android/android-relativelayout-with-
examples
Relative Layout

Source: https://www.tutlane.com/tutorial/android/android-relativelayout-with-
examples
Frame Layout
Framelayout is a ViewGroup subclass which is used to
specify the position of View instances it contains on the
top of each other to display only single View inside the
FrameLayout.

In simple manner, we can say FrameLayout is designed to


block out an area on the screen to display a single item.

It act as a placeholder on the screen and it is used to


hold a single child view.

The child views are added in a stack and the most


recently added child will show on the top. We can add
multiple children views to FrameLayout and control their
position by using gravity attributes in FrameLayout.

Source: https://www.tutlane.com/tutorial/android/android-framelayout-with-examples
Frame Layout

Source: https://www.tutlane.com/tutorial/android/android-framelayout-with-examples
Frame Layout

Source: https://www.tutlane.com/tutorial/android/android-framelayout-with-examples
Table Layout
TableLayout is a ViewGroup subclass which is used to
display the child View elements in rows and columns.

It position its children elements into rows and columns


and it won’t display any border lines for rows, columns or
cells.

The TableLayout in android will work same as HTML table


and table will have as many columns as the row with the
most cells. The TableLayout can be explained
as <table> and TableRow is like <tr> element.

Source: https://www.tutlane.com/tutorial/android/android-tablelayout-with-examples
Table Layout
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="100dp"
android:paddingLeft="10dp"
android:paddingRight="10dp" >

<TableRow android:background="#0079D6" android:padding="5dp">

other views here…

</TableRow>

</TableLayout>

Source: https://www.tutlane.com/tutorial/android/android-framelayout-with-examples
Table Layout

Source: https://www.tutlane.com/tutorial/android/android-framelayout-with-examples
Table Layout

Source: https://www.tutlane.com/tutorial/android/android-framelayout-with-examples
WebView Layout
WebView is an extension of View class and it is used to
show the static HTML web pages content or remote web
pages content with URL in android applications as a part
of our activity layout.

Generally, in android the WebView will act as an


embedded browser to include the web pages content in
our activity layout and it won’t contain any features of
normal browser, such as address bar, navigation controls,
etc.

Source: https://www.tutlane.com/tutorial/android/android-webview-with-examples
WebView Layout
XML

Java

Source: https://www.tutlane.com/tutorial/android/android-webview-with-examples
WebView Layout

Source: https://www.tutlane.com/tutorial/android/android-webview-with-examples
ListView Layout
ListView is a ViewGroup which is used to display the list
of scrollable of items in multiple rows and the list items
are automatically inserted to the list using an adapter.

Adapter acts as an intermediate between the data


sources and adapter views such as ListView, Gridview to
fill the data into adapter views. The adapter will hold the
data and iterates through an items in data set and
generate the views for each item in the list.

Source: https://www.tutlane.com/tutorial/android/android-listview-with-examples
ListView Layout
Generally, in android we have a different types of adapters available to fetch the data from different data
sources to fill the data into adapter views, those are

Source: https://www.tutlane.com/tutorial/android/android-listview-with-examples
ListView Layout

Source: https://www.tutlane.com/tutorial/android/android-listview-with-examples
ListView Layout

Source: https://www.tutlane.com/tutorial/android/android-listview-with-examples
ListView Layout

Source: https://www.tutlane.com/tutorial/android/android-listview-with-examples
GridView Layout
Grid View is a ViewGroup which is used to display items
in a two dimensional, scrollable grid and grid items are
automatically inserted to the gridview layout using a list
adapter.

Source: https://www.tutlane.com/tutorial/android/android-gridview-with-examples
GridView Layout

Source: https://www.tutlane.com/tutorial/android/android-gridview-with-examples
GridView Layout

ImageAdapter.java

Source: https://www.tutlane.com/tutorial/android/android-gridview-with-examples
GridView Layout

Source: https://www.tutlane.com/tutorial/android/android-gridview-with-examples
GridView Layout

Source: https://www.tutlane.com/tutorial/android/android-gridview-with-examples
< Controls >
Controls
Input controls are the interactive components in your app's user interface.
Android provides a wide variety of controls you can use in your UI, such as
buttons, text fields, seek bars, check box, zoom buttons, toggle buttons,
and many more.

Source: https://www.tutorialspoint.com/android/android_user_interface_controls.htm
Controls
A View is an object that draws something on the screen that the user can interact with
and a ViewGroup is an object that holds other View (and ViewGroup) objects in order to
define the layout of the user interface.

Source: https://www.tutorialspoint.com/android/android_user_interface_controls.htm
Controls
There are number of UI controls provided by Android that allow you to build the
graphical user interface for your app.
TextView This control is used to display text to the user.
EditText A predefined subclass of TextView that includes rich editing
capabilities.
AutoCompleteTextView A view that is similar to EditText, except that it shows a list of
completion suggestions
ButtonA A push-button that can be pressed, or clicked, by the user to
perform an action.
ImageButtonAn An AbsoluteLayout which enables you to specify the exact location
of its children. This shows a button with an image (instead of text)
that can be pressed or clicked by the user
Source: https://www.tutorialspoint.com/android/android_user_interface_controls.htm
Controls
CheckBox An on/off switch that can be toggled by the user. You should use
check box when presenting users with a group of selectable
options that are not mutually exclusive.
ToggleButton An on/off button with a light indicator.
RadioButton The RadioButton has two states: either checked or unchecked.
RadioGroup A RadioGroup is used to group together one or more RadioButtons.
ProgressBar The ProgressBar view provides visual feedback about some
ongoing tasks, such as when you are performing a task in the
background.
Spinner A drop-down list that allows users to select one value from a set.
TimePicker The TimePicker view enables users to select a time of the day, in
either 24-hour mode or AM/PM mode.
DatePicker The DatePicker view enables users to select a date of the day.
Source: https://www.tutorialspoint.com/android/android_user_interface_controls.htm
Creating Controls
A view object may have a unique ID assigned to it which will identify the View uniquely
within the tree.

Source: https://www.tutorialspoint.com/android/android_user_interface_controls.htm
Creating Controls
Create an instance of the Control object and capture it from the layout in your Java
activity file

Source: https://www.tutorialspoint.com/android/android_user_interface_controls.htm
DEMONSTRATION

Creating UI Layout and UI


Controls
< Events >
Event Handling
An event listener is an interface in the View class that contains a single callback method.
These methods will be called by the Android framework when the View to which the
listener has been registered is triggered by user interaction with the item in the UI.
Event Handler Event Listener Description
onClick() OnClickListener() This is called when the user either clicks or touches or
focuses upon any widget like button, text, image etc. You
will use onClick() event handler to handle such event.
onLongClick() OnLongClickListener() This is called when the user either clicks or touches or
focuses upon any widget like button, text, image etc. for
one or more seconds. You will use onLongClick() event
handler to handle such event.
onFocusChange() OnFocusChangeListener() This is called when the widget looses its focus ie. user
goes away from the view item. You will use
onFocusChange() event handler to handle such event.
Source: https://developer.android.com/guide/topics/ui/ui-events
Event Handling
Event Handler Event Listener Description
onKey() OnFocusChangeListener() This is called when the user is focused on the item and
presses or releases a hardware key on the device. You
will use onKey() event handler to handle such event.
onTouch() OnTouchListener() This is called when the user either clicks or touches or
focuses upon any widget like button, text, image etc. for
one or more seconds. You will use onLongClick() event
handler to handle such event.
onFocusChange() OnFocusChangeListener() This is called when the user presses the key, releases the
key, or any movement gesture on the screen. You will use
onTouch() event handler to handle such event.
onMenuItemClick() OnMenuItemClickListener() This is called when the user selects a menu item. You will
use onMenuItemClick() event handler to handle such
event.
onCreateContextM onCreateContextMenuItem This is called when the context menu is being built(as the
enu() Listener() Source:result of a sustained "long click)
https://developer.android.com/guide/topics/ui/ui-events
Event Implementation
implement the nested interface in your Activity or define it as an anonymous class

Source: https://developer.android.com/guide/topics/ui/ui-events#java
Event Implementation
Implement OnClickListener as a part of your Activity. This will avoid the extra class load and object
allocation.

Source: https://developer.android.com/guide/topics/ui/ui-events#java
DEMONSTRATION

Event Handling
References
• https://www.tutlane.com/tutorial/android/android-ui-layouts-linear-relative-frame-table-listview-
gridview-webview

• https://www.tutorialspoint.com/android/android_user_interface_layouts.htm

• https://www.tutlane.com/tutorial/android/android-ui-controls-textview-edittext-radio-button-checkbox

• https://www.tutorialspoint.com/android/android_user_interface_controls.htm

You might also like