Professional Documents
Culture Documents
Ma Ques Imp
Ma Ques Imp
By the help of activity, you can place all your UI components or widgets in a single
screen.
The 7 lifecycle method of Activity describes how activity will behave at different
states.
Method Description
onResume called when activity will start interacting with the user.
android:textAlignmen
t Used to the text alignment in the dropdown list.
android:gravity Used to specify the gravity of the view like center, top,
XML attributes Description
bottom, etc
Steps Description
1 You will use Android studio to create an Android application and name it as
AndroidSpinnerExample under a package com.example.spinner.
4 No need to define default string constants. Android studio takes care of default
string constants at string.xml
5 Run the application and choose a running android device and install the application
on it and verify the results.
3 .Intents
In Android, it is quite usual for users to witness a jump from one application to
another as a part of the whole process, for example, searching for a location on the
browser and witnessing a direct jump into Google Maps or receiving payment links
in Messages Application (SMS) and on clicking jumping to PayPal or GPay (Google
Pay). This process of taking users from one application to another is achieved by
passing the Intent to the system. Intents, in general, are used for navigating among
various activities within the same application, but note, is not limited to one single
application, i.e., they can be utilized from moving from one application to another
as well.
Intents could be Implicit, for instance, calling intended actions and explicit as well,
such as opening another activity after some operations like onClick or anything
else. Below are some application of Intents:
1. Sending the User to Another App
2. Getting a Result from an Activity
3. Allowing Other Apps to Start Your Activity
Or
1) Implicit Intent
For example, you may write the following code to view the webpage.
1. Intent intent=new Intent(Intent.ACTION_VIEW);
2. intent.setData(Uri.parse("http://www.javatpoint.com"));
3. startActivity(intent);
2) Explicit Intent
Explicit Intent specifies the component. In such case, intent provides the external
class to be invoked.
1. Intent i = new Intent(getApplicationContext(), ActivityTwo.class);
2. startActivity(i);
3. View and view group
The View class is the base class or we can say that it is the superclass for all the GUI
components in android. For example, the EditText class is used to accept the input
from users in android apps, which is a subclass of View, and another example of the
TextView class which is used to display text labels in Android apps is also a subclass
of View.
Or the other definition,
View refer to the android.view.View class, which is the base class of all UI classes.
android.view.View class is the root of the UI class hierarchy. So from an object
point of view, all UI objects are View objects. Following are some of the common
View subclasses that will be used in android applications.
TextView
EditText
ImageView
RadioButton
Button
ImageButton
CheckBox
DatePicker
Spinner
ProgressBar and etc.
These are some of the view subclass available in android.
ViewGroup
The ViewGroup class is a subclass of the View class. And also it will act as a base
class for layouts and layouts parameters. The ViewGroup will provide an invisible
container to hold other Views or ViewGroups and to define the layout properties.
For example, Linear Layout is the ViewGroup that contains UI controls like Button,
TextView, etc., and other layouts also. ViewGroup Refer to
the android.view.ViewGroup class, which is the base class of some special UI
classes that can contain other View objects as children. Since ViewGroup objects
are also View objects, multiple ViewGroup objects and View objects can be
organized into an object tree to build a complex UI structure. Following are the
commonly used ViewGroup subclasses used in android applications.
FrameLayout
WebView
ListView
GridView
LinearLayout
RelativeLayout
TableLayout and many more.
The ViewGroup subclasses listed above group View instances together and takes
care of their layout. For instance, the LinearLayout will render the components
after each other either horizontally or vertically.
View ViewGroup
View is a simple
rectangle box that
responds to the user’s ViewGroup is the invisible container. It holds View and
actions. ViewGroup
A View object is a
component of the
user interface (UI) like
a button or a text box, A ViewGroup object is a layout, that is, a container of
and it’s also called a other ViewGroup objects (layouts) and View objects
widget. (widgets)
CheckBox, etc.
android.view.View
which is the base class
of all UI classes. ViewGroup is the base class for Layouts.
4. Layouts
Android Layout is used to define the user interface that holds the UI controls or
widgets that will appear on the screen of an android application or activity screen.
Generally, every application is a combination of View and ViewGroup. As we know,
an android application contains a large number of activities and we can say each
activity is one page of the application. So, each activity contains multiple user
interface components and those components are the instances of the View and
ViewGroup. All the elements in a layout are built using a hierarchy
of View and ViewGroup objects.
View- A View is defined as the user interface which is used to create interactive UI
components such as TextView, ImageView, EditText, RadioButton, etc., and is
responsible for event handling and drawing. They are Generally Called Widgets.
A ViewGroup act as a base class for layouts and layouts parameters that hold other
Views or ViewGroups and to define the layout properties. They are Generally Called
layouts.
The Android framework will allow us to use UI elements or widgets in two ways:
Use UI elements in the XML file
Create elements in the Kotlin file dynamically
Linear Layout
Relative Layout
Constraint Layout
Table Layout
Frame Layout
List View
Grid View
Absolute Layout
WebView
ScrollView
These are the types of layouts and out of them we’ll learn about the two very
important layouts:
1. Linear Layout
We use this layout to place the elements in a linear manner. A Linear manner means
one element per line. This layout creates various kinds of forms on Android. In this,
arrangement of the elements is in a top to bottom manner.
This layout is for specifying the position of the elements in relation to the other
elements that are present there.
In the relative layout, alignment of the position of the elements to the parent
container is possible. To define it in such a way, we write the following:
android:layout_alignParentTop= “true”
android:layout_alignParentLeft= “true”
Android Constraint Layout: ConstraintLayout is a ViewGroup subclass, used
to specify the position of layout constraints for every child View relative to
other views present. A ConstraintLayout is similar to a RelativeLayout, but
having more power.
Android Frame Layout: FrameLayout is a ViewGroup subclass, used to
specify the position of View elements it contains on the top of each other to
display only a single View inside the FrameLayout.
Android Table Layout: TableLayout is a ViewGroup subclass, used to display
the child View elements in rows and columns.
Android Web View: WebView is a browser that is used to display the web
pages in our activity layout.
Android ListView: ListView is a ViewGroup, used to display scrollable lists of
items in a single column.
Android Grid View: GridView is a ViewGroup that is used to display a
scrollable list of items in a grid view of rows and columns.
The following are the attributes for customizing a Layout while defining it:
2. Explicit Intent
Explicit Intent specifies the component. In such a case, intent provides the external
class to be invoked.
Intent i = new Intent(getApplicationContext(), ActivityTwo.class);
startActivity(i);
Example:
In the below example, there are two activities (FirstActivity, SecondActivity). When
you click on the ‘GO TO OTHER ACTIVITY’ Button in the FirstActivity, then you move
to the SecondActivity. When you click on the ‘GO TO HOME ACTIVITY’ button in the
SecondActivity, then you move to the first activity. This is getting done through
Explicit Intent.
UI testing, also known as GUI testing, is a technique for testing the features of any
software that a user will interact with. This usually involves testing the visual
components to ensure that they are meeting the outlined requirements - both in
terms of functionality and performance.
It involves testing all visual indicators and graphical icons, including menus, radio
buttons, text boxes, checkboxes, toolbars, colors, fonts, and more.
Visual Design
Functionality
Usability
Performance
Compliance
UI testing is centered around two main things. First, checking how the
application handles user actions carried out using the keyboard, mouse, and
other input devices. Second, checking whether visual elements are displayed
and working correctly.
It is only by doing this that organizations can ensure that applications meet
their functional requirements and that end-users will successfully adopt them.
For this reason, UI testing plays a significant role before an application is
released to production.
1. Manual Testing
In manual testing, a human tester performs a set of operations to check whether the
application is functioning correctly and that the graphical elements conform to the
documented requirements. Manual-based testing has notable downsides in that it
can be time-consuming, and the test coverage is extremely low. Additionally, the
quality of testing in this approach depends on the knowledge and capabilities of the
testing team.
2. Record-and-Playback Testing
3. Model-Based Testing
In this testing approach, we focus on building graphical models that describe the
behavior of a system. This provides a deeper understanding of the system, which
allows the tester to generate highly efficient test cases. In the models, we determine
the inputs and outputs of the system, which are in turn, used to run the tests. Model-
based testing works as follows:
Create a model for the system
Determine system inputs
Verify the expected output
Execute tests
Check and validate system output vs. the expected output
Steps Description
1 You will use Android studio to create an Android application under a package
com.tutorialspoint.myapplication.
5 Modify layout XML file res/layout/view.xml add any GUI component if required.
6 Run the application and choose a running android device and install the application
on it and verify the results.
But according to the complexity of the application, there are various types of
color can be chosen.
Have a look at the following image, having selected the primary color, with that
the Complementary color can be chosen or Analogous color can be chosen
or Triadic color can be chosen or Secondary color can be chosen to meet the
required style.
These methods are also can be applied for the material design buttons, text
fields, chips, floating action buttons, cards, navigation bars, bottom sheets, etc.
These features are available with the Material design components out of the
proverbial box. Just need to add the dependency of the material design
components and start implementing the styling for material design components.
Date date= Calendar.getInstance().getTime(); // this will get the date and the time
java.text.DateFormat date_format; //This will get the standard format
Date_format = android.text.format.DateFormat.getDateFormat(this);
And for Time:
1 Afrikanns
Code: af. Folder name: values-af
Arabic
2
Code: ar. Folder name: values-ar
Bengali
3
Code: bn. Folder name: values-bn
Czech
4
Code: cs. Folder name: values-cs
Chinese
5
Code: zh. Folder name: values-zh
German
6
Code: de. Folder name: values-de
French
7
Code: fr. Folder name: values-fr
Japanese
8
Code: ja. Folder name: values-ja
Example
To experiment with this example , you can run this on an actual device or in an
emulator.
Steps Description
1 You will use Android studio to create an Android application under a package
com.example.sairamkrishna.myapplication.
4 Run the application and choose a running android device and install the application
on it and verify the results
</ScrollView>
Android ListView is a view which groups several items and display them in vertical
scrollable list. The list items are automatically inserted to the list using
an Adapter that pulls content from a source such as an array or database.
An adapter actually bridges between UI components and the data source that fill
data into UI Component. Adapter holds the data and send the data to adapter view,
the view can takes the data from adapter view and shows the data on different
views like as spinner, list view, grid view etc.
The ListView and GridView are subclasses of AdapterView and they can be
populated by binding them to an Adapter, which retrieves data from an external
source and creates a View that represents each data entry.
Android provides several subclasses of Adapter that are useful for retrieving
different kinds of data and building views for an AdapterView ( i.e. ListView or
GridView). The common adapters are ArrayAdapter,Base
Adapter, CursorAdapter, SimpleCursorAdapter,SpinnerAdapter and WrapperListA
dapter. We will see separate examples for both the adapters.
ListView Attributes
1 android:id
This is the ID which uniquely identifies the layout.
2 android:divider
This is drawable or color to draw between list items.
3 android:dividerHeight
This specifies height of the divider. This could be in px, dp, sp, in, or mm.
4 android:entries
Specifies the reference to an array resource that will populate the ListView.
5 android:footerDividersEnabled
When set to false, the ListView will not draw the divider before each footer view.
The default value is true.
6 android:headerDividersEnabled
When set to false, the ListView will not draw the divider after each header view.
The default value is true.
ArrayAdapter
You can use this adapter when your data source is an array. By default,
ArrayAdapter creates a view for each array item by calling toString() on each item
and placing the contents in a TextView. Consider you have an array of strings you
want to display in a ListView, initialize a new ArrayAdapter using a constructor to
specify the layout for each string and the string array −
ArrayAdapter adapter = new
ArrayAdapter<String>(this,R.layout.ListView,StringArray);
Here are arguments for this constructor −
First argument this is the application context. Most of the case, keep it this.
Second argument will be layout defined in XML file and having TextView for
each string in the array.
Final argument is an array of strings which will be populated in the text view.
Once you have array adapter created, then simply call setAdapter() on
your ListView object as follows −
ListView listView = (ListView) findViewById(R.id.listview);
listView.setAdapter(adapter);
You will define your list view under res/layout directory in an XML file. For our
example we are going to using activity_main.xml file.
Example
Following is the example which will take you through simple steps to show how to
create your own Android application using ListView. Follow the following steps to
modify the Android application we created in Hello World Example chapter −
Step Description
1 You will use Android Studio IDE to create an Android application and name it
as ListDisplay under a package com.example.ListDisplay as explained in the Hello
World Example chapter.
3 No need to change string.xml, Android studio takes care of default string constants.
6 Run the application to launch Android emulator and verify the result of the changes
done in the application.