ELECT22222
ELECT22222
Buttons:
Button - is used to perform an action every time the
user clicks it. This contains a text view inside it to
inform the user on what is the function of this button.
Image button - this button displays the image
instead of Text, and it performs an action. This is
usually used in product selling applications.
Checkbox - allows the user to select one or more
options. It is usually used in some type of form such
as registration form, login form, exam, and quizzes.
You can use this if the user can choose one or more
answers based on the question.
Android Studio Classic workspace:
A. Menu Bar: Located at the very top the user can Radio button - allows the user to select one option.
find the File Menu option that contains various Usually, this button is used to determine a single
menus and settings related to file and project answer from the list of choices.
handlings. *However, you need to use Radio Group to ensure the
B. Tool Bar: Shows the tools and actions that are application can select one in the options.
frequently used by the user. Toggle button - or simply called a switch, it is a
C. Navigation Bar: Allows the user to easily navigate button that allows you to control and change settings
and move around the files and folders of the project. between two different states (On/Off).
D. Editor Window: Shows the content of the file that
the user is currently working on. Widgets:
E. Status Bar: Displays messages that give Image view - displays an image/pictures, ex. Bitmap,
information such as code errors, warnings, png, drawables, etc., this is to add a user interface
successful status. more exciting. You can also use this as a profile
F. Project Tool Window: Shows a hierarchical view of picture, product picture, and any other use depends
the files and folders of the project. on what the application requires.
View and viewgroup Web view - allows you to display the content of a
A View is a building block that represents the user website inside your application.
interface of your application, and it occupies a Video view - allows you to display a video file from
rectangular area in the application. You can simply your application.
call this a (child), and this child is responsible for Calendar view - this widget allows you to display and
event handling and creating an interactive user select a date from the calendar view.
interface.
Layouts:
TEXT: Constraint layout - this is a layout that allows the
Text View - it is a user interface that is utilized to set programmer to size and position widgets in a flexible
and show the Text or content depending on the user’s user interface.
needs. Linear layout - this layout arranges views into a
EditText - A user interface element for entering and single row vertically and single columns in a
modifying text. Its default input type is plain text horizontal way.
Frame layout - allows you to block a single area and 4. layout: A layout defines the visual structure for a
display an item in the front of the screen. user interface, such as the UI for an Android
Table layout - is a layout that you can arrange into application. This folder stores Layout files that are
rows and columns, and it consists of a number of written in XML language. You can add additional
table rows and column objects. layout objects or widgets as child elements to
gradually build a View hierarchy that defines your
Containers: layout file.
Spinner - is a view that let the user pick among the 5. mipmap: Mipmap folder contains the Image Asset
listed item inside this child. In other programs, they file that can be used in Android Studio application.
call this a drop-down box. You can generate the following icon types like
ListView - Displays a vertically-scrollable collection Launcher icons, Action bar and tab icons, and
of views, where each view is positioned immediately Notification icons.
below the previous view in the list. 6. colors.xml: colors.xml file contains color
GridView - A view that shows items in two- resources of the Android application. Different color
dimensional scrolling grid. values are identified by a unique name that can be
Recycler view - it is a flexible and combination of used in the Android application program.
ListView and GridView. 7. strings.xml: The strings.xml file contains string
Scroll view - this allows the view place within it to be resources of the Android application. The different
scrolled. You can place only one direct child inside string value is identified by a unique name that can
this view. be used in the Android application program. This file
also stores string array by using XML language.
Google: 8. styles.xml: The styles.xml file contains resources
Ad view - is a view that you can set and display a of the theme style in the Android application. This file
banner and ads in your application. is written in XML language.
Map view - is a view that you can set and display a 9. build.gradle(Module:app): This defines the
map in your application, and it obtains data from module-specific build configurations. Here you can
google maps. add dependencies what you need in your Android
application.
PROJECT TOOL WINDOW
Within an Android project structure, the most
frequently edited folders are:
1. AndroidManifest.xml: The manifest file is an
important part of our app because it defines the
structure and metadata of our application, its
components, and its requirements.
2. Java: The Java folder contains the Java source
code files. These files are used as a controller for
controlled UI (Layout file). It gets the data from the
Layout file and after processing that data output will
be shown in the UI layout. It works on the backend of
an Android application.
3. drawable: A Drawable folder contains resource
type file (something that can be drawn). Drawable
may take a variety of file like Bitmap (PNG, JPEG),
Nine Patch, Vector (XML), Shape, Layers, States,
Levels, and Scale.
UNIT 3: Spinner
ANDROID USER INTERFACE ● Allow a user to select one value from the list of
values.
View Layouts
● View is the basic building block for user interface ● The ViewGroup is a subclass of View and provides
which is created from the View class. invisible container that HOLD other Views or other
● A view occupies a rectangular area on the screen ViewGroups and define their layout properties.
and is responsible for drawing and event handling. ● When talking about ViewGroup, we are talking
● View is the base class for widgets, which are used generally about Layout.
to create interactive UI components like buttons,
textviews, etc. A Layout defines the visual structure for an Android
● View also is the base class for ViewGroups that can user interface.
serve as a container of widgets or other ViewGroups. ● There are many layouts in Android and each
layouts has its own purpose, pros, and cons.
Layout Attributes
● android:id: This is the ID which uniquely identifies
the view.
● android:layout width: This is the width of the
layout.
● android:layout_height: This is the height of the
layout.
To solve this, instead of using anonymous class for There are 3 ways on how we can add input controls to
the handlers. Create a separate method that will our android application.
handle the events. 1. Through XML
2. On runtime (Programmatically) (Unit 5)
Using Layout file activity_main.xml to specify event 3. Combination of the two method (Inflater) (Unit 5)
handler directly.
Android TextView
Getting and Setting Value to a View ● In android, TextView is a user interface control
Toast, Logs, and Dialog which is used to set and display the text to the user
TOAST based on our requirements.
● The TextView control will act as like label control
and it won’t allow users to edit the text.
LOG
Create a TextView in Layout File
DIALOG
Create a EditText in Layout File Define Button Click Event in XML Layout File
● We can define click event handler for button by
adding android:onClick attribute to the element in
our XML layout file.
Android Button
● In android, Button is a user interface control which
is used to perform an action whenever the user click
or tap on it.
● Generally, Buttons in android will contains a text or
an icon or both and perform an action when user
touches it.
Android Button Control Attributes Create ToggleButton in XML Layout File
Create Android Spinner in XML Layout File The adapter requires parameter to be initialized, for
In android, we can create Spinner in XML layout file example an array adapter, it requires context, the
using element with different attributes like as shown individual layout and the data.
below.
Android DatePickerDialog
In android, you can pick a date using DatePicker. The
problem is, this datepicker eats the whole screen
Android TimePickerDialog
entirely. The solution is to use datepicker dialog
In android, you can pick a date using TimePicker. Like
instead, which will produce a modal(dialog) like
datepicker, timepicker also eatup the whole screen.
effect in displaying the picker itself.
To solve this, use timepicker dialog instead.
Before diving in to date and time picker, let us learn
Using the variables from Calendar that we declared
the basic of calendar method in android first. Declare
earlier, let us declare timepicker dialog with context
new calendar variable before the onCreate. Declare
as first parameter, the Listener as second and
other necessary variable that may contain the details
hoursOfDay and minute as follows and lastly the
of our current date and time.
Boolean which is 24hours view.