Professional Documents
Culture Documents
Android Programming Question Bank 2023-24 (Mid Sem Exam) - Final
Android Programming Question Bank 2023-24 (Mid Sem Exam) - Final
(DIPLOMA STUDIES)
PARUL UNIVERSITY, POST LIMDA, WAGHODIA,
GUJARAT 391760
QUESTION BANK
ENROLLMENT NO.
NAME
Semester 6th
Division
SUBJECT NAME ANDROID PROGRAMMING
SUBJECT CODE 03606352
ACADEMIC YEAR 2023-24
Android Programming (03606352) PIET-DS
Ans:
Version Name of Version
Android 1.0 Alpha,
Android 1.1 Beta,
Android 1.5 Cupcake,
Android 1.6 Donut,
Android 2.0 Eclair,
Android 2.2 Froyo,
Android 2.3 Gingerbread,
Android 3.0 Honeycomb,
Android 4.0 Ice Cream Sandwhich,
Android 4.1 Jellybean,
Android 4.4 Kitkat,
Android 5.0 Lolipop,
Android 6.0 Marshmallow,
Android 7.0 Nougat,
Android 8.0 Oreo,
Android 9.0 Pie,
Android 10.0 Q,
Android 11.0 R,
Android 12.0 Snow Corn,
Android 13.0 Tiramishu
Ans:
The hierarchy pattern is a standard site structure with an index page and a series of sub-
pages. If you are designing a responsive site you may be restricted to this, however
introducing additional patterns could allow you to tailor the experience for mobile. Luke
Wroblewski’s Mobile First approach helps us focus on the important stuff first: features
and user journeys that will help us create great user experiences.
Ans:
A hub and spoke pattern gives you a central index from which users will navigate out.
It’s the default pattern on Apple’s iPhone. Users can’t navigate between spokes but must
return to the hub, instead. This has historically been used on desktop where a workflow is
restricted (generally due to technical restrictions such as a form or purchasing process)
however this is becoming more prevalent within the mobile landscape due to users being
focused on one task, as well as the form factor of the device, making a global navigation
more difficult to use.
Ans:
First generation mobile networks were reliant upon analogue radio systems which
meant that users could only make phone calls, they couldn’t send or receive text
messages. The 1G network was first introduced in Japan in 1979 before it was
rolled out in other countries such as the USA in 1980. In order to make it work,
cell towers were built around the country which meant that signal coverage could
be obtained from greater distances. However, the network was unreliable and had
some security issues. For instance, cell coverage would often drop, it would
experience interference by other radio signals and due to a lack of encryption, it
could easily be hacked. This means that with a few tools, conversations could be
heard and recorded.
The 1G network was not perfect, but it remained until remained until 1991 when
it was replaced with 2G. This new mobile network ran on digital signal, not
analogue, which vastly improved its security but also its capacity. On 2G, users
could send SMS and MMS messages (although slowly and often without success)
and when GPRS was introduced in 1997, users could receive and send emails on
the move.
Ans: Types of mobile application can be divided into three categories as follows:
1. Native Apps
Anything natural to our environment is known as native. Similar is the case of a
mobile application. If an app is natural to the mobile then it is considered as a
Native app, which means, apps that are built targeting a particular mobile which
means a particular Operating System (like Android, Windows, macOS, etc.) of
the mobile.
These apps work only on those devices for which they are built.
If an app is developed for Apple mobiles i.e. macOS, then that app will not work
on any other device which is having an operating system other than macOS.
If an app is developed for Android OS then it will work only on devices having
Android OS, and not on any other device.
The benefits of native apps are that it easily communicates with the device on
which it is running, It easily communicates with device hardware like Camera,
Speakers, Graphics Engine, Buttons, Touch, Location Sensors and
Accelerometers, etc.
The page rendering i.e. User Interface rendering goes on without any hanging
issues or stucking up.
The flow of layout is flawless and easy to use.
These apps are more user-friendly, easier to operate, and can easily tolerate a load
of fast user activity on them.
These apps can react at the same speed with what the user operates them.
These apps in terms of interactivity supersede all other types of apps.
2. Web Apps
These are apps built using web technologies and they serve web pages using the
existing web browsers on devices.
These are built using HTML, Javascript, jQuery, CSS, etc.
These are not exactly mobile apps but a website in its responsive form in the form
of a mobile application, which means, a web-based application which works on
any mobile device or operating system because it is delivered using web browsers
inside a mobile device.
They are a responsive form of websites so they automatically change their
appearance according to the device and space available for the rendering of
content.
A category of Web apps is Progressive Web Apps (PWA) which are native apps
running inside a browser. Plugins, third-party plugins or APIs cannot be used in
these kinds of apps
3. Hybrid Apps
The term hybrid means “mixture”. Thus, a hybrid app refers to applications that
are native as well as web-based. Hybrid apps are an integration of Native and
Web apps. These apps use web technologies and native APIs, both.
These apps can use most of the device features like native apps. Similar to web
apps, hybrid apps are made of web technologies like HTML, CSS, Javascript,
jquery, AJAX, JSON, etc.
These also use web browsers to display content and user interfaces but they use
the native elements as well as web-based elements for development.
The code of these apps is just needed to be tweaked to make it compatible across
multiple platforms.
Ans: Android Debug Bridge (adb) is a versatile command-line tool that lets you communicate
with a device. The ADB is typical, used to communicate with a smartphone, tablet,
smartwatch, set-top box, or any other device that can run the Android operating system.
We can do things on an Android device that may not be suitable for everyday use, like,
install apps outside of the Play Store, debug apps, access hidden features, and bring up a
UNIX shell, etc. For security reasons, Developer Options need to be unlocked and you
need to have USB Debugging Mode enabled as well. Not only that, but you also need to
authorize USB Debugging access to the specific PC that you’re connected to with a USB
cable. It is a client-server program that includes three components.
A client, which sends commands. The client runs on your development machine. You can
invoke a client from a command-line terminal by issuing an adb command.
A daemon, which runs commands on a device. The daemon runs as a background process
on each device.
A server, which manages communication between the client and the daemon. The server
runs as a background process on your development machine.
Ans: App permissions help support user privacy by protecting access to the following:
Restricted data, such as system state and users' contact information Restricted actions,
such as connecting to a paired device and recording audio
Types of Permissions
Install-Time Permissions: If the Android 5.1.1 (API 22) or lower, the permission is
requested at the installation time at the Google Play Store.
If the user Accepts the permissions, the app is installed. Else the app installation is
canceled.
Run-Time Permissions: If the Android 6 (API 23) or higher, the permission is requested
at the run time during the running of the app.
If the user Accepts the permissions, then that feature of the app can be used. Else to use
the feature, the app requests permission again.
So, now the permissions are requested at runtime. In this article, we will discuss how to
request permissions in an Android Application at run time.
It is responsible to protect the application to access any protected parts by providing the
permissions.
It also declares the android api that the application is going to use.
It lists the instrumentation classes. The instrumentation classes provides profiling and
other informations. These informations are removed just before the application is
published etc.
This is the required xml file for all the android application and located inside the root
directory.
<manifest xmlns:android=http://schemas.android.com/apk/res/android
package="com.javatpoint.hello"
android:versionCode="1" android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" />
<application android:icon="@drawable/ic_launcher" android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity" android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
The elements used in the above xml file are described below.
<manifest>
manifest is the root element of the AndroidManifest.xml file. It has package attribute that
describes the package name of the activity class.
<application>
application is the subelement of the manifest. It includes the namespace declaration. This
element contains several subelements that declares the application component such as
activity etc.
The commonly used attributes are of this element are icon, label, theme etc.
android:icon represents the icon for all the android application components.
android:label works as the default label for all the application components.
android:theme represents a common theme for all the android activities.
<activity>
activity is the subelement of application and represents an activity that must be defined in
the AndroidManifest.xml file. It has many attributes such as label, name, theme,
launchMode etc.
android:label represents a label i.e. displayed on the screen.
android:name represents a name for the activity class. It is required attribute.
<intent-filter>
intent-filter is the sub-element of activity that describes the type of intent to which
activity, service or broadcast receiver can respond to.
<action>
It adds an action for the intent-filter. The intent-filter must have at least one action
element.
<category>
It adds a category name to an intent-filter.
Ans:
Linux kernel
At the bottom of the layers is Linux - Linux 3.6 with approximately 115 patches. This
provides a level of abstraction between the device hardware and it contains all the
essential hardware drivers like camera, keypad, display etc. Also, the kernel handles all
the things that Linux is really good at such as networking and a vast array of device
drivers, which take the pain out of interfacing to peripheral hardware.
Libraries
On top of Linux kernel there is a set of libraries including open-source Web browser
engine WebKit, well known library libc, SQLite database which is a useful repository for
storage and sharing of application data, libraries to play and record audio and video, SSL
libraries responsible for Internet security etc.
Android Libraries
This category encompasses those Java-based libraries that are specific to Android
development. Examples of libraries in this category include the application framework
libraries in addition to those that facilitate user interface building, graphics drawing and
database access. A summary of some key core Android libraries available to the Android
developer is as follows –
android.app − Provides access to the application model and is the cornerstone of all
Android applications.
Having covered the Java-based core libraries in the Android runtime, it is now time to
turn our attention to the C/C++ based libraries contained in this layer of the Android
software stack.
Android Runtime
This is the third section of the architecture and available on the second layer from the
bottom. This section provides a key component called Dalvik Virtual Machine which is a
kind of Java Virtual Machine specially designed and optimized for Android.
The Dalvik VM makes use of Linux core features like memory management and multi-
threading, which is intrinsic in the Java language. The Dalvik VM
enables every Android application to run in its own process, with its own instance of the
Dalvik virtual machine.
The Android runtime also provides a set of core libraries which enable Android
application developers to write Android applications using standard Java programming
language.
Application Framework
The Application Framework layer provides many higher-level services to applications in
the form of Java classes. Application developers are allowed to make use of these
services in their applications.
Activity Manager − Controls all aspects of the application lifecycle and activity stack.
Content Providers − Allows applications to publish and share data with other
applications.
View System − An extensible set of views used to create application user interfaces.
Applications
You will find all the Android application at the top layer. You will write your application
to be installed on this layer only. Examples of such applications are Contacts Books,
Browser, Games etc.
1. src — Contains the .java source files for your project. In this example, there is one
file, HelloworldActivity.java. The HelloworldActivity.java file is the source file
for your activity. You will write the code for your application in this file.
2. Android 2.3 library — This item contains one file, android.jar, which contains all
the class libraries needed for an Android application.
3. gen — Contains the R.java file, a compiler-generated file that references all the
resources found in your project. You should not modify this file.
4. assets — This folder contains all the assets used by your application, such as
HTML, text files, databases, etc.
5. res — This folder contains all the resources used in your application. It also
contains a few other subfolders: drawable-<resolution>, layout, and values.
1) Activity
Activity is the most used of the four components. It is always used in an app.
Activity is basically a screen in an application. There may be multiple activities in
an app as an app may contain multiple screens. Each activity consists of various
UI components like Views, buttons, layouts, etc. The Activity consists of an
Activity class where all the work is done.
2) Service
Services are the processes that execute in the background but not displayed on the
screen. These are used when you want programs to run but not necessarily display
it on the UI screen. For example, playing music in an app, and changing the music
automatically, doesn’t need to be displayed on the screen and just needs to keep
running in the background. Services can be started and managed from activities,
intent receivers, etc and are given higher priority by android runtime than many
other processes.
3) Intents
Intent basically provides a developer with the option to move from one screen to
another screen. It gives the option to connect one screen to another. It consists of
the operation to be performed and the activity class name has to be declared to
which the current activity has to be connected.
4) Intent Receiver
Intent Receiver is used when a function has to be executed in response to an
event. This doesn’t display UI but may alert the user with a notification.
5) Content Provider
Content providers deal with the sharing of data within or between apps. Apps can
store data in shared preferences, SQLite databases, files, etc. An application can
allow other apps to access their data by defining a Content Provider. The data’s
access is provided by a Universe Resource Identifier (URI) defined by the
Content Provider.
Hybrid Widgets: These Android widgets combine all three of the previous
features.
Lifecycle Description
Method
onCreate() This method called when the activity is first
created
onStart() This method is called when the activity
become visible to the user
onResume() This is called when the user start interacting
with the application
onPause() The paused activity does not received 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
destroy by the system.
5. Write down steps for deploying android app in physical mobile devices.(3 marks)
• The 'Android Device Chooser' will open. If device connected successfully, it will
be listed under 'Choose a running Android device.' Select device and click 'OK.'
• Connect android phone with the pc on which running project. eclipse/ map
• Let it install smartphone, go all the necessary drivers. When done, open your
seetings then goto : Settings > Applications > Development > USB debugging and
enable it on by clicking on the check button at the right side.
• Also, enable Settings > Unknown resources
• Come back to eclipse on pc. Right click on the project/application, Run As > Run
configurations... >Choose Device>Target Select device Run.
• Click on the Target tab from top. By default it is on the first tab Android
• Choose the second radio button which says Launch on all compatible
Devices/AVDs. Then click Apply at the bottom and afterwards, click Run.
• It will automatically install application's .apk file into Smartphone and make it run
over it., just like on emulator.
onCreate()
The activity is created in this state.The OS calls the onCreate() method whenever
an activity gains memory.
onStart()
This callback is called by the system whenever the activity enters the Started
state.As the app prepares for the activity to enter the foreground and become
interactive, the onStart() call makes the activity visible to the user. This method,
for instance, is where the app initializes the UI- maintaining code.
onResume()
The system calls the onResume() callback when the activity enters the Resumed
state and enters the foreground. In this state, the app communicates with the user.
Until something draws attention away from the app, the app stays in this state.
Receiving a phone call, navigating to another activity, or turning off the device
screen are all examples of such events.
onPause()
Although it does not always imply that the activity is being destroyed, the system
refers to this method as the initial sign that the user is leaving your activity; It tells
the user that the activity is no longer in the foreground, though it might still be
visible if the user is in multi-window mode.
onStop()
When an activity is hidden from the user, it is referred to as stopped. Any activity
is halted in the event that it is replaced by another activity. For instance, suppose a
user was on screen1, clicked a button, and then moved on to screen2. Activity that
is displaying content for screen 1 will be stopped in this case. When the user
presses the back navigation button, all activities are halted before they can
continue. As a result, the Activity will be in the stopped state when it is replaced
by other activities that the user has initiated or switched. As a result, the
application will cease to provide the user with any useful information.
onRestart()
After the stop state, the activity is called in the restart state.Therefore, the
onRestart() function of the activity is called when the user returns to the screen or
resumes the activity that was stopped.To put it another way, onRestart() is never
called when the operating system starts the activity for the first time.It is only
called when activity resumes after being stopped.
onDestroy()
When it is not in the background, any activity is referred to as being
destroyed.Activity can be destroyed in a variety of circumstances. First, if the user
presses the back navigation button, the activity will end after it completes the
pause and stop lifecycle.
Code :MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
Log.d("lifecycle","onCreate INvoked");
}
protected void onStart()
{
super.onStart();
Log.d("lifecycle","onStart invoked");
}
protected void onResume()
{
super.onResume();
Log.d("lifecycle","onResume invoked");
}
protected void onPause()
{
super.onPause();
Log.d("lifecycle","onPause invoked");
}
protected void onStop()
{
super.onStop();
Log.d("lifecycle","onStop invoked");
}
protected void onRestart()
{
super.onRestart();
Log.d("lifecycle","onRestart invoked");
}
protected void onDestroy()
{
super.onDestroy();
Log.d("lifecycle","onDestroy invoked");
}
}
Ans: An intent is to perform an action on the screen. It is mostly used to start activity, send
broadcast receiver, start services and send message between two activities. There are two
intents available in android as Implicit Intents and Explicit Intents. Here is a sample
example to start new activity with old activity.
Intent is to perform an action. It is mostly used to start activity, send broadcast receiver,
start services and send message between two activities. There are two intents available in
android as Implicit Intents and Explicit Intents.
Explicit Intent − It going to connect the internal world of an application such as start
activity or send data between two activities. To start new activity we have to create Intent
object and pass source activity and destination activity as shown below −
Note: And we should declare about second activity in Manifest.xml file or else it going to
show run time exception. sample declaration is as shown below.
<activity android:name = ".SecondActivity"></activity>
Implicit Intents − It going to connect with out side application such as call, mail,
phone,see any website ..etc. In implicit intent we have to pass an action using setAction()
as shown below example.
Ans: 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.
For Example :
when that event happens, then the register receivers get notified. There are mainly two
types of Broadcast Receivers:
Static Broadcast Receivers: These types of Receivers are declared in the manifest file and
works even if the app is closed.
Dynamic Broadcast Receivers: These types of receivers work only if the app is active or
minimized.
The two main things that we have to do in order to use the broadcast receiver in our
application are:
IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED).also
{
// receiver is the broadcast receiver that we have registered
// and it is the intent filter that we have created registerReceiver(receiver,it)
}
1. px(screen pixels)
2. in(physical inches)
3. pt(physical points)
4. mm(physical millimeters)
5. dp(density-independent pixels)
6. sp(scale-independent pixels)
For Example:
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle=”bold”
android:textSize=”20dp”
android:hint=“Enter Your Name" />
6. List out different layout in android and explain any 2 out of them.(3 marks)
Ans: Types of Android Layout
Ans: Android Toggle Button can be used to display checked/unchecked (On/Off) state on the
button. It is beneficial if user have to change the setting between two states. It can be
used to On/Off Sound, Wifi, Bluetooth etc.
Since Android 4.0, there is another type of toggle button called switch that provides slider
control.
Method Description
CharSequence getTextOff() Returns the text when button is not in the
checked state.
CharSequence getTextOn() Returns the text for when button is in the
checked state.
void setChecked(boolean Changes the checked state of this button.
checked)
For Example:
File: activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ToggleButton
android:id="@+id/toggleButton" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_marginLeft="8dp"
android:layout_marginTop="80dp" android:text="ToggleButton" android:textOff="Off"
android:textOn="On"
app:layout_constraintEnd_toStartOf="@+id/toggleButton2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ToggleButton
android:id="@+id/toggleButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="60dp"
android:layout_marginTop="80dp"
android:text="ToggleButton"
android:textOff="Off"
android:textOn="On"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="144dp"
android:layout_marginLeft="148dp"
android:text="Submit"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</android.support.constraint.ConstraintLayout>
File: MainActivity.java
package example.javatpoint.com.togglebutton;
@Override
public void onClick(View view) { StringBuilder result = new StringBuilder();
result.append("ToggleButton1 : ").append(toggleButton1.getText());
result.append("\nToggleButton2:
").append(toggleButton2.getText());
//Displaying the message in toast Toast.makeText(getApplicationContext(),
result.toString(),Toast.LENGTH_LONG).show();
}
});
}
}
Ans: Android Spinner is like the combox box of AWT or Swing. It can be used to display the
multiple options to the user in which only one item can be selected by the user.
Android spinner is like the drop down menu with multiple values from which the end
user can select only one value.
Android spinner is associated with AdapterView. So you need to use one of the adapter
classes with spinner.
File: activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="example.javatpoint.com.spinner.MainActivity">
<Spinner android:id="@+id/spinner"
android:layout_width="149dp"
android:layout_height="40dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.502"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.498"
/>
</android.support.constraint.ConstraintLayout>
File: MainActivity.java
package example.javatpoint.com.spinner;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
//Getting the instance of Spinner and applying
OnItemSelectedListener on it
Spinner spin = (Spinner) findViewById(R.id.spinner);
spin.setOnItemSelectedListener(this);
//Creating the ArrayAdapter instance having the country list ArrayAdapter aa = new
ArrayAdapter(this,android.R.layout.simple_spinner_item,country);
aa.setDropDownViewResource(android.R.layout.simple_spinner_dro pdown_item);
//Setting the ArrayAdapter data on the Spinner spin.setAdapter(aa);
Output:
Ans: In android, CheckBox is a two-states button that can be either checked (ON) or
unchecked (OFF) and it will allow users to toggle between the two states (ON / OFF)
based on the requirements. Generally, we can use multiple CheckBox controls in android
application to allow users to select one or more options from the set of values.
By default, the android CheckBox will be in the OFF (Unchecked) state. We can change
the default state of CheckBox by using android:checked attribute. In case, if we want to
change the state of CheckBox to ON (Checked), then we need to set android:checked =
“true” in our XML layout file.
In android, we can create CheckBox control in two ways either in the XML layout file or
create it in the Activity file programmatically.
Attribute Description
android:id It is used to uniquely identify the control
android:checked It is used to specify the current state of checkbox
It is used to specify how to align the text like left, right,
android:gravity
center, top, etc.
android:text It is used to set the text for a checkbox.
android:textColor It is used to change the color of text.
android:textSize It is used to specify the size of text.
It is used to change the style (bold, italic, bold italic) of
android:textStyle
text.
android:background It is used to set the background color for checkbox
control.
android:padding It is used to set the padding from left, right, top and bottom.
For Example:
<CheckBox
android:id="@+id/chkJava"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_marginTop="150dp"
android:layout_marginLeft="100dp"
android:text="Java"
android:onClick="onCheckboxClicked"/>
<CheckBox
android:id="@+id/chkPython"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_marginLeft="100dp"
android:text="Python"
android:onClick="onCheckboxClicked"/>
Ans: Android WebView is used to display web page in android. The web page can be loaded
from same application or URL. It is used to display online content in android activity.
Android WebView uses webkit engine to display web page.
The android.webkit.WebView is the subclass of AbsoluteLayout class.
The loadUrl() and loadData() methods of Android WebView class are used to load and
display web page.
activity_main.xml
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/webView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
File: activity_main.xml
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="fill_parent"/>
Create an additional mylist.xml file in layout folder which contains view components
displayed in listview.
mylist.xml
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:padding="2dp"
android:textColor="#4d4d4d"/>
Now place the list of data in strings.xml file by creating string-array. File:strings.xml
<resources>
<string name="app_name">ListView</string>
<string-array name="array_technology">
<item>Android</item>
<item>Java</item>
<item>Php</item>
</string-array>
</resources>
File: MainActivity.java
listView=(ListView)findViewById(R.id.listView);
textView=(TextView)findViewById(R.id.textView);
listItem = getResources().getStringArray(R.array.array_technology); final
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, listItem);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
Toast.makeText(getApplicationContext(),value,Toast.LENGTH_SHORT).show();
}}
13. Explain android Analog clock and Digital clock with example.(4 marks)
Ans: The android.widget.AnalogClock and android.widget.DigitalClock classes provides the
functionality to display analog and digital clocks.
Android analog and digital clocks are used to show time in android application.
Android DigitalClock is the subclass of TextView class. Since Android API level 17, it is
deprecated. You are recommended to use TextClock Instead.
The AnalogClock was deprecated in API level 23. This widget is no longer supported.
Instead if you want to use AnalogClock in your application you need to hard code. It does
not appear in API level 27 to drag from palette.
In android, you need to drag analog and digital clocks from the pallet to display analog
and digital clocks.
File: activity_main.xml
<DigitalClock
android:id="@+id/digitalClock1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/analogClock1"
android:layout_centerHorizontal="true"
android:layout_marginLeft="176dp"
android:layout_marginTop="84dp"
android:text="DigitalClock"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />