1 CTH EDUCATION
Unit – 03 : Mobile Computing
Fragments life cycle, List fragment, Dialog fragment.
Interaction between fragments.
"Understanding the components of a screen (Layouts),
Adapting to display orientation.
Action Bar & Progress Bar.
Views (UI Widgets)-Button,
Toast and Spinner,
Toggle Button, Check Box and Radio Button,
Web View, List View, Edit Text,
Date Picker and Time Picker,
Analog and Digital clock,
Questions to be discussed?
1. What is Fragment in Android? Also explain its type.
2. Explain Fragments life cycle in details.
3. What is screen orientation? Explain types of android screen orientation.
4. Differentiate between Analog and Digital clock.
5. Write short notes on:
a) Action Bar
b) Progress Bar
c) UI Widgets
d) Android Toast
Diploma : CSE (All Paper) By : Alok Sir (Mob. No.: +91-80 84 370 470)
2 CTH EDUCATION
What is fragment in Android?
In Android, the fragment is the part of Activity.
There can be more than one fragment in an activity.
Fragments represent multiple screen inside one activity.
Fragments can exist only inside an activity as its lifecycle is dependent on the lifecycle of host activity.
For example, if the host activity is paused, then all the methods and operations of the fragment
related to that activity will stop functioning, thus fragment is also termed as sub-activity.
Fragments can be added, removed, or replaced dynamically i.e., while activity is running.
<fragment> tag is used to insert the fragment in an android activity layout.
Types of Android Fragments:
1. Single Fragment
2. List Fragment
3. Fragment Transaction
Single Fragment:
Display only one single view on the device screen.
This type of fragment is mostly used for mobile phones.
List Fragment:
This Fragment is used to display a list-view from which the user can select the desired sub-activity.
The menu drawer of apps like Gmail is the best example of this kind of fragment.
Fragment Transaction:
This kind of fragments supports the transition from one fragment to another at run time.
Users can switch between multiple fragments like switching tabs.
Diploma : CSE (All Paper) By : Alok Sir (Mob. No.: +91-80 84 370 470)
3 CTH EDUCATION
Fragment Life Cycle:
As we know that the fragment is the part of an Activity.
Android fragments have their own life cycle very similar to an android activity.
The list of methods in a fragment class is :
onAttach()
onCreate()
onCreateView()
onActivityCreated()
onStart()
onResume()
onPause()
onStop()
onDestroyView()
onDestroy()
Interaction between Fragment:
As we know that the fragment is the part of an Activity.
There can be a number of fragments within one activity and they have their own life cycle.
Now a day most apps have so many features so that they use multiple fragments in a single app.
Communication is one of the important parts of apps for sharing data from one fragment to another.
Two fragments can’t communicate directly.
There are multiple ways in which we can communicate within apps:
1. We can communicate within fragments using the ViewModel.
2. We can also communicate between fragments using Interface.
Adapting Android Screen Orientation :
The screen Orientation is the attribute of an activity element.
Screen Orientation is also known as screen rotation.
The orientation of android activity can be portrait, landscape, sensor, unspecified etc.
You need to define it in the AndroidManifest.xml file.
When screen orientation change from one state to other, it is also known as configuration change.
Diploma : CSE (All Paper) By : Alok Sir (Mob. No.: +91-80 84 370 470)
4 CTH EDUCATION
The common values for screen Orientation attribute are as follows:
Value Description
unspecified It is the default value. In such case, system chooses the orientation.
portrait taller not wider
landscape wider not taller
sensor orientation is determined by the device orientation sensor.
What is UI widget in an Android?
A widget is a small gadget or control of your android application placed on the home screen.
It is an element of a graphical UI that displays information or provides a specific way for a user to
interact with an application.
There are various android widgets such as
Button,
Edit Text,
Toggle Button,
Date Picker,
Time Picker,
Progress Bar etc.
Android Button:
A button consists of text or an icon that communicates what action occurs when the user press it.
Edit Text:
It is a Widget of user interface (UI) used to retrieve and modify text data from a user in an Android app.
Edit Text is a subclass of Text View that inherit all the property of Text View.
Android Toast:
Displays information for the short duration of time.
Diploma : CSE (All Paper) By : Alok Sir (Mob. No.: +91-80 84 370 470)
5 CTH EDUCATION
Toggle Button:
It has two states ON/OFF.
Check Box:
Checkboxes allow the user to select one or more options from a set.
Radio button:
Radio buttons allow the user to select one option from a set.
Spinner:
A spinner is a graphical GUI widget that allows a user to modify the value in the adjacent text box by
either clicking the up or down arrow, or holding the up or down arrow.
It also allowing the value to increase or decrease.
Date Picker:
Date picker displays the date picker dialog that can be used to pick the date.
Time Picker:
Time Picker displays the time picker dialog that can be used to pick the time.
Action Bar in Android :
Android Action Bar is a menu bar that present at the top of the activity screen in android.
Action Bar can contain menu items which become visible when the user click.
Android Action Bar was launched by Google in 2013 with the release of Android 3.0.
Before that, the name of the action bar was App Bar.
App Bar contains only the name of the application or current activity.
Progress Bar in Android:
In Android, Progress Bar is a graphical view indicator that shows some progress.
Android progress bar displays a bar representing the completing of the task.
Progress bar in android is useful since it gives the user an idea of time to finish its task.
It displays the status of progress of the given task (such as downloading an image) to the user.
Diploma : CSE (All Paper) By : Alok Sir (Mob. No.: +91-80 84 370 470)
6 CTH EDUCATION
Android Toast:
Toast can be used to display information for the short period of time.
A toast contains message to be displayed quickly and disappears after sometime.
A toast provides simple feedback about an operation in a small popup.
It only fills the amount of space required for the message and the current activity.
Toasts automatically disappear after a timeout.
Digital clock :
This type of clock shows numbers to display the time in a digital format.
Digital clocks are often called as Electronic Clocks.
Recent clocks are showing Date, Day, Month, Year, Temperature etc.
Digital clocks are developed by Thomas Bromley in 1961.
Analog clock :
A clock is called "analog" when it has moving hands and hours marked from 1 to 12 to show time.
There are three hands in a clock, the hour hand, the minute hand, and the second hand.
Initially invented in the Netherlands by Christian Huygens in 1656.
What is the difference between digital and analog clock?
Digital Clock Analog Clock
A digital clock uses only numbers to show the An analog clock uses an hour hand and a minute
time. hand to show the time.
Digital clock uses digital technology. Analog clock uses analog technology.
In digital technology, translation of information In Analog technology, information is translated into
is into binary format (zero or one). electric pulses.
Digital clocks are more accurate than analog. Analog clocks are less accurate than digital clock.
It has more features with respect to analog clock. It has less features with respect to digital clock.
Digital clock is less expansive. Analog clock is more expansive.
Diploma : CSE (All Paper) By : Alok Sir (Mob. No.: +91-80 84 370 470)