0% found this document useful (0 votes)
161 views31 pages

QB Solution PT-1 MAD

The document provides information about features of the Android OS, the Open Handset Alliance (OHA), and tools used to develop Android applications. The key points are: 1. The Android OS has features like a beautiful UI, connectivity options, storage using SQLite, media support, messaging, web browsing, multi-touch, multi-tasking, resizable widgets, support for multiple languages, and technologies like GCM, WiFi Direct, and Android Beam. 2. The OHA is a consortium headed by Google to develop open standards for mobile devices and provide a better consumer experience at a lower cost. 3. Tools to develop Android apps include Android Studio, DDMS, Draw 9

Uploaded by

Aryan Buchake
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
161 views31 pages

QB Solution PT-1 MAD

The document provides information about features of the Android OS, the Open Handset Alliance (OHA), and tools used to develop Android applications. The key points are: 1. The Android OS has features like a beautiful UI, connectivity options, storage using SQLite, media support, messaging, web browsing, multi-touch, multi-tasking, resizable widgets, support for multiple languages, and technologies like GCM, WiFi Direct, and Android Beam. 2. The OHA is a consortium headed by Google to develop open standards for mobile devices and provide a better consumer experience at a lower cost. 3. Tools to develop Android apps include Android Studio, DDMS, Draw 9

Uploaded by

Aryan Buchake
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

Question Bank Answers

CT- I

Course: MOBILE APPLICATION DEVELOPMENT (MAD)


Course Code:22617 Program:CO6I Semester: VI

Chapter 1: ANDROID AND ITS TOOLS


2 Marks
1.Enlist Features Of Android OS?
Beautiful UI
1 Android OS basic screen provides a beautiful and intuitive user
interface.

Connectivity
2 GSM/EDGE, IDEN, CDMA, EV-DO, UMTS, Bluetooth, Wi-Fi, LTE, NFC
and WiMAX.

Storage
3 SQLite, a lightweight relational database, is used for data storage
purposes.

Media support
4 H.263, H.264, MPEG-4 SP, AMR, AMR-WB, AAC, HE-AAC, AAC 5.1,
MP3, MIDI, Ogg Vorbis, WAV, JPEG, PNG, GIF, and BMP.

Messaging
5
SMS and MMS

Web browser
6 Based on the open-source WebKit layout engine, coupled with
Chrome's V8 JavaScript engine supporting HTML5 and CSS3.

Multi-touch
7 Android has native support for multi-touch which was initially made
available in handsets such as the HTC Hero.
Multi-tasking
8 User can jump from one task to another and same time various
application can run simultaneously.

Resizable widgets
9 Widgets are resizable, so users can expand them to show more
content or shrink them to save space.

Multi-Language
10
Supports single direction and bi-directional text.

GCM
Google Cloud Messaging (GCM) is a service that lets developers send
11
short message data to their users on Android devices, without
needing a proprietary sync solution.

Wi-Fi Direct
12 A technology that lets apps discover and pair directly, over a high-
bandwidth peer-to-peer connection.

Android Beam
13 A popular NFC-based technology that lets users instantly share, just
by touching two NFC-enabled phones together.

2.What Is OHA?
The Open Handset Alliance (OHA) is a association whose goal is to develop open
standards for mobile devices, promote innovation in mobile phones and provide a better
experience for consumers at a lower cost.The OHA is the group that is in charge of the
Android smartphones operating system. It was created by Google.
The Open Handset Alliance (OHA) is consortium of multiple companies like Samsung,
Sony, Intel and many more to provide services and deploy handsets using android
platform.

3.Enlist Tools To Develop Android Application?


android
1 This tool lets you manage AVDs, projects, and the installed
components of the SDK

ddms
2
This tool lets you debug Android applications

3 Draw 9-Patch
This tool allows you to easily create a NinePatch graphic using a
WYSIWYG editor

emulator
4
This tools let you test your applications without using a physical device

mksdcard
5 Helps you create a disk image (external sdcard storage) that you can
use with the emulator

proguard
6
Shrinks, optimizes, and obfuscates your code by removing unused code

sqlite3
7 Lets you access the SQLite data files created and used by Android
applications

traceview
8 Provides a graphical viewer for execution logs saved by your
application

Adb
Android Debug Bridge (adb) is a versatile command line tool that lets
9
you communicate with an emulator instance or connected Android-
powered device.

4 Marks
1.Explain Android Ecosystem?
Ecosystem in Market terminology refers to the inter-dependence between demand and
supply.
In the Android ecosystem this translates to inter-dependence between users,
developers, and equipment makers. One cannot exist without the other:
Users- buy devices and applications
Equipment makers- sell devices, sometimes bundled with applications
Developers- buy devices, then make and sell applications
2.Explain the Android architecture in detail.
Android architecture or Android software stack is categorized into five parts:
1. Linux kernel
2. native libraries (middleware),
3. Android Runtime
4. Application Framework
5. Applications

1) Linux kernel
It is the heart of android architecture that exists at the root of android
architecture. Linux kernel is responsible for device drivers, power management,
memory management, device management and resource access.
2) Native Libraries
Running on the top of the kernel, the Android framework was developed with various
features. It consists of various C/C++ core libraries with numerous of open source tools.
Some of these are:
1. The Android runtime:
The Android runtime consist of core libraries of Java and ART(the Android
RunTime). Older versions of Android (4.x and earlier) had Dalvik runtime.
2. Open GL(graphics library):
This cross-language, cross-platform application program interface (API) is used to
produce 2D and 3D computer graphics.
3. WebKit:
This open source web browser engine provides all the functionality to display web
content and to simplify page loading.
4. Media frameworks:
These libraries allow you to play and record audio and video.
5. Secure Socket Layer (SSL):
These libraries are there for Internet security.
3) Android Runtime
In android runtime, there are core libraries and DVM (Dalvik Virtual Machine) which is
responsible to run android application. DVM is like JVM but it is optimized for mobile
devices. It consumes less memory and provides fast performance.
4) Android Framework
On the top of Native libraries and android runtime, there is android framework. Android
framework includes Android API's such as UI (User Interface), telephony, resources,
locations, Content Providers (data) and package managers. It provides a lot of classes
and interfaces for android application development.
1. Activity Manager:
It manages the activity lifecycle and the activity stack.
2. Telephony Manager:
It provides access to telephony services as related subscriber information, such as
phone numbers.
3. View System:
It builds the user interface by handling the views and layouts.

4. Location manager:
It finds the device’s geographic location.
5) Applications
On the top of android framework, there are applications. All applications such as home,
contact, settings, games, browsers are using android framework that uses android
runtime and libraries. Android runtime and native libraries are using linux kernal.
3.Differentiate between JVM and DVM.

Chapter 2 – INSTALLATION & CONFIGURATION OF ANDROID

2 Marks
1.What Is SDK?
Android SDK is a collection of libraries and Software Development tools that are essential
for Developing Android Applications. Whenever Google releases a new version or update of
Android Software, a corresponding SDK also releases with it. In the updated or new version
of SDK, some more features are included which are not present in the previous version.
Android SDK consists of some tools which are very essential for the development of Android
Application. These tools provide a smooth flow of the development process from developing
and debugging. Android SDK is compatible with all operating systems such as Windows,
Linux, macOS, etc.
2.What Is Emulator?
An Android Emulator is a device that simulates an Android device on your system. Suppose
we want to run our android application that we code. One option is that we will run this on
our Android Mobile by Enabling USB Debugging on our mobile. Another option is using
Android Emulator. In Android Emulator the virtual android device is shown on our system on
which we run the Android application that we code.
Thus, it simply means that without needing any physical device Android SDK component
“Android Emulator” provides a virtual device on the System where we run our Application.
The emulator’s come with the configuration for Various android phones, tablets, Wear OS,
and Android TV devices.

3.What Is ADT?
ADT (Android Developer Tools) is a plugin for Eclipse that provides a suite of tools that are integrated with the
Eclipse IDE. It offers you access to many features that help you develop Android applications quickly. ADT
provides GUI access to many of the command line SDK tools as well as a UI design tool for rapid prototyping,
designing, and building of your application's user interface.

Because ADT is a plugin for Eclipse, you get the functionality of a well-established IDE, along with Android-specific
features that are bundled with ADT. The following describes important features of Eclipse and ADT:

Integrated Android project creation, building, packaging, installation, and debugging


ADT integrates many development workflow tasks into Eclipse, making it easy for you to rapidly develop
and test your Android applications.
SDK Tools integration
Many of the SDK tools are integrated into Eclipse's menus, perspectives, or as a part of background
processes ran by ADT.

4 Marks
1.Compare JVM and DVM?

2.Explain DVM With Diagram?


As we know the modern JVM is high performance and provides excellent memory
management. But it needs to be optimized for low-powered handheld devices as well.
The Dalvik Virtual Machine (DVM) is an android virtual machine optimized for mobile
devices. It optimizes the virtual machine for memory, battery life and performance.
Dalvik is a name of a town in Iceland. The Dalvik VM was written by Dan Bornstein.
The Dex compiler converts the class files into the .dex file that run on the Dalvik VM.
Multiple class files are converted into one dex file.

Fig.: The compiling and packaging process from the source file

The javac tool compiles the java source file into the class file.
The dx tool takes all the class files of your application and generates a single .dex file. It
is a platform-specific tool.
The Android Assets Packaging Tool (aapt) handles the packaging process.

3.Describe The Concept Of Android SDK?


The Android SDK (Software Development Kit) is a set of software tools and resources provided by Google
for developers to create applications (apps) for the Android operating system. It plays a crucial role in the
development of Android apps and provides the following functions:

App Development Tools: The Android SDK includes a suite of development tools, the most important
of which is Android Studio. Android Studio is the official integrated development environment (IDE) for
Android app development. It offers features like code editing, debugging, performance profiling, and a
visual layout editor to streamline the app development process.
SDK Components: The Android SDK provides a range of libraries, frameworks, and APIs (Application
Programming Interfaces) that developers can use to build Android apps. These components cover a wide
range of functionality, including user interface design, data storage, networking, multimedia, and more.

Emulator: The Android SDK includes an emulator that allows developers to test their apps on virtual
Android devices with different screen sizes, resolutions, and hardware configurations. This helps ensure
that apps work properly on various devices before being deployed to real smartphones or tablets.

Platform Tools: The SDK includes a set of platform tools that are essential for various tasks during app
development and debugging. These tools include ADB (Android Debug Bridge) for device
communication, Fastboot for flashing Android devices, and other command-line utilities.

Documentation and Samples: The Android SDK provides extensive documentation, guides, and code
samples to assist developers in learning how to create Android apps and solve common development
challenges. Developers can access this information online or offline through Android Studio.

Android Virtual Device Manager (AVD Manager): AVD Manager is a tool within Android Studio that
allows developers to create, configure, and manage virtual Android devices for testing. Developers can
define device specifications, such as screen size, version of Android, and hardware properties.

Updates and Compatibility: The SDK is regularly updated to support new versions of Android and
provide developers with the latest features and improvements. This helps ensure that apps can take
advantage of the latest capabilities and maintain compatibility with newer Android versions.

Distribution and Deployment: The Android SDK assists developers in preparing apps for distribution
through the Google Play Store and other app stores. It provides tools for signing, packaging, and
optimizing apps for deployment to Android devices.

4.Write Down Steps How To Create AVD In Android Studio?


1. Open the Device Manager.
2. Click Create Device. The Select Hardware window appears. ...
3. Select a hardware profile, then click Next. ...
4. Select the system image for a particular API level, and then click Next.
5. Change the AVD properties as needed, and then click Finish.
Explain each step in detail

5.Write Down The Steps How To Install Android Studio?

1. Unpack the .zip .


2. Copy the android-studio folder into your Program Files folder.
3. Open the android-studio > bin folder.
4. Launch studio64.exe (for 64-bit machines) or studio.exe (for 32-bit machines).
5. Follow the Setup Wizard in Android Studio and install any recommended SDK packages.
Expalain more
3. UI components and Layouts
2 marks.
1. List layouts in android UI design.
Linear Layout
Relative Layout
Frame Layout
Table Layout
Web View
List View
Grid View
2. List different attributes of Frame layout.
android:id. This is the unique id which identifies the layout in the R. ...
android:foreground. Foreground defines the drawable to draw over the content and
this may be a color value. ...
android:foregroundGravity. ...
android:visibility. ...
android:measureAllChildren.
3. List different attributes of Table layout.
android:id
This is the ID which uniquely identifies the layout.

android:collapseColumns
This specifies the zero-based index of the columns to collapse. The column indices
must be separated by a comma: 1, 2, 5.

android:shrinkColumns
The zero-based index of the columns to shrink. The column indices must be
separated by a comma: 1, 2, 5.

android:stretchColumns
The zero-based index of the columns to stretch. The column indices must be
separated by a comma: 1, 2, 5.
4 marks.

1. What is use of AndroidManifest.xml file in any android


application?
The AndroidManifest.xml file contains information of your
package, including components of the application such as
activities, services, broadcast receivers, content providers etc.

It performs some other tasks also:

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.
<manifest ... >
<application ... >
<activity android:name=".MainActivity" ... >
...
</activity>
</application>
</manifest>

2. Explain following files.


I. Main activity file
In Android application development, MainActivity.java is typically the
default activity that is launched when your app starts. It's a Java class that
extends the AppCompatActivity class and overrides methods like onCreate()
to define what happens when the activity is created.
II. Manifest file

The AndroidManifest.xml file contains information of your


package, including components of the application such as
activities, services, broadcast receivers, content providers etc.

III. String file


A single string that can be referenced from the application or from other resource
files (such as an XML layout). Note: A string is a simple resource that is referenced
using the value provided in the name attribute (not the name of the XML file).
IV. Layout file
A layout file defines the structure for a user interface in your app, such as in an
activity. All elements in the layout are built using a hierarchy of View and ViewGroup
objects. A View usually draws something the user can see and interact with. A
ViewGroup is an invisible container that defines the layout structure for View and
other ViewGroup objects
2. What are view and viewgroup classes in android? Why layouts are
created using xml file?
View
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.

3. List and Explain the Resource files.

res (Resources) Folder (omit diagram)


It’s an important folder that will contain all non-code resources, such as bitmap images, UI strings, XML layouts like
as shown below.

The res (Resources) will contain a different type of folders that are
Drawable Folder (res/drawable)
It will contain the different types of images as per the requirement of application. It’s a best practice to add all the
images in a drawable folder other than app/launcher icons for the application development.

Layout Folder (res/layout)


This folder will contain all XML layout files which we used to define the user interface of our application. Following
is the structure of the layout folder in the android application.

Mipmap Folder (res/mipmap)


This folder will contain app / launcher icons that are used to show on the home screen. It will contain different
density type of icons such as hdpi, mdpi, xhdpi, xxhdpi, xxxhdpi, to use different icons based on the size of the
device.

Following is the structure of the mipmap folder in the android application.


Values Folder (res/values)
This folder will contain various XML files, such as strings, colors, style definitions and a static array of strings or
integers. Following is the structure of the values folder in android application.

4. Designing User interface with View.


2 marks.
1. List view classes in android application development.
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.
2. Explain attributes wrap_content and match_parent with
respect to viewgroups.
 In Android development, there are two common ways to define width and height. They
are wrap_content and match_parent. But how do we know when to use the two of them. Let’s
take a closer look.
 Wrap_content
 The wrap_content, as the name suggests, it wraps the content based on the content or the values
of the element. For example, a textview has a text value of “This is a text”. The width of the
textview will depend on the text that you entered. As a result, the width of the textview will match
the content it has and it won’t occupy more spaces than expected.
 Match_parent
 The match_parent, as the name suggests, it matches the parent’s size. For example, the width or
the height of the parent. It is used to create an element that matches the size of the parent’s
width or height. If you want to have an image that extends from the entire width or height of the
screen, you can use match_parent to achieve it.
 In the image below, you can visualize the difference of wrap_content from match_parent.

4 marks.
1. What is TextView & EditText? Explain TextView attributes.
Android TextView is a user interface which displays the text to the
user.
The EditText is a user interface which is used for entering and
changing the text. While using edit text in XML layout, we must
specify its inputType attribute which configures the keyboard
according to input type mention.

Attribute Description

android: id It is used to uniquely identify the control


android:autoLink It will automatically found and convert URLs and
email

addresses as clickable links.

android: ems It is used to make the textview be exactly this many


ems wide.

android:hint It is used to display the hint text when text is empty

android:width It makes the TextView be exactly this many pixels


wide.

android:height It makes the TextView be exactly this many pixels


tall.

android:text It is used to display the text.

android:textColor It is used to change the color of the text.

android:gravity It is used to specify how to align the text by the


view's x and y-
axis.

android:maxWidth It is used to make the TextView be at most this


many pixels wide.

android:minWidth It is used to make the TextView be at least this


many pixels wide.

android:textSize It is used to specify the size of the text.

android:textStyle It is used to change the style (bold, italic,


bolditalic) of text.
2. Develop a program to display following output using suitable layout
and views.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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">

<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button" />

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center_vertical"
android:text="Button" />

<Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Button" />

<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/button3"
android:layout_marginBottom="9dp"
android:text="Button" />

<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/button3"
android:layout_alignParentEnd="true"
android:layout_marginBottom="7dp"
android:layout_toEndOf="@id/button4"
android:text="Button" />

<Button
android:id="@+id/button6"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_above="@id/button5"
android:layout_below="@id/button"
android:layout_alignParentRight="true"
android:text="Button" />

</RelativeLayout>
3. Develop the registration form using the following GUI (assume suitable
layout )
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:background="#795AB0DF"
android:paddingLeft="80dp"
android:paddingRight="80dp"
android:orientation="vertical"
tools:context=".MainActivity">

<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:layout_marginLeft="44dp"
android:text="Register"
android:textColorHighlight="#0091EA"
android:textSize="48sp"
/>

<EditText
android:id="@+id/editTextText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="44dp"
android:ems="10"
android:hint="Name"
android:inputType="text"
android:minHeight="48dp"
/>

<EditText
android:id="@+id/editTextText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:ems="10"
android:hint="Email"
android:inputType="text"
android:minHeight="48dp"
/>

<EditText
android:id="@+id/editTextText3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="36dp"
android:ems="10"
android:hint="Password"
android:inputType="text"
android:minHeight="48dp"
/>

<EditText
android:id="@+id/editTextText4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="44dp"
android:ems="10"
android:hint="Confirm Password"
android:inputType="text"
android:minHeight="48dp"/>

<Button
android:id="@+id/button"
android:layout_width="171dp"
android:layout_height="51dp"
android:layout_marginTop="44dp"
android:layout_marginLeft="40dp"
android:text="Sign Up" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Have an Account? Login Here"
android:layout_marginTop="44dp"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
/>

</LinearLayout>
4. Develop a calculator with basic operation (XML and Java File)(Assume
suitable layout and UI views)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="abhiandroid.com.calculater.MainActivity"
android:orientation="vertical"
android:gravity="top"
android:textAlignment="center"
android:background="@android:color/holo_blue_bright"
android:weightSum="1">

<TextView
android:text="@string/enter_two_numbers"
android:layout_width="match_parent"
android:id="@+id/textView"
android:layout_height="30dp"
android:gravity="center_horizontal"
android:textColorLink="?android:attr/editTextColor"
tools:textStyle="bold|italic"
android:textStyle="bold|italic"
android:fontFamily="serif"
android:visibility="visible"
android:textSize="24sp"
android:layout_weight="0.07" />

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="@+id/editOp1"
android:textSize="18sp"
android:gravity="center_horizontal"
android:layout_marginBottom="5dp"
android:visibility="visible" />

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="@+id/editOp2"
android:textSize="18sp"
android:gravity="center_horizontal"
android:elevation="1dp" />

<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<Button
android:text="+"
android:layout_width="78dp"
android:layout_height="wrap_content"
android:id="@+id/btnadd"
android:layout_weight="0.03" />

<Button
android:text="-"
android:layout_width="78dp"
android:layout_height="wrap_content"
android:id="@+id/btnsub"
android:layout_weight="0.03" />

<Button
android:text="*"
android:layout_width="78dp"
android:layout_height="wrap_content"
android:id="@+id/btnmul"
android:layout_weight="0.03"/>
<Button
android:text="/"
android:layout_height="wrap_content"
android:id="@+id/btndiv"
android:layout_width="78dp"
android:layout_weight="0.03" />

<Button
android:text="Clear"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:id="@+id/btnclr"
android:layout_weight="0.03" />
</LinearLayout>

<TextView
android:text="@string/result"
android:layout_width="332dp"
android:id="@+id/textView1"
android:layout_marginTop="10dp"
android:layout_height="50dp"
android:gravity="center_horizontal"
android:textColorLink="?android:attr/editTextColor"
tools:textStyle="bold|italic"
android:textStyle="bold|italic"
android:fontFamily="serif"
android:visibility="visible"
android:textSize="30sp" />

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="@+id/result"
android:textSize="18sp"
android:text="0.00"
android:gravity="center_horizontal" />
</LinearLayout>

Java file
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


private EditText opr1;
private EditText opr2;
private Button btnadd;
private Button btnsub;
private Button btnmul;
private Button btndiv;
private Button btnclr;
private TextView txtresult;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
opr1 = (EditText) findViewById(R.id.editOp1);
opr2 = (EditText) findViewById(R.id.editOp2);
btnadd = (Button) findViewById(R.id.btnadd);
btnsub = (Button) findViewById(R.id.btnsub);
btnmul = (Button) findViewById(R.id.btnmul);
btndiv = (Button) findViewById(R.id.btndiv);
btnclr = (Button) findViewById(R.id.btnclr);
txtresult= (TextView) findViewById(R.id.result);
// Addition
btnadd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if((opr1.getText().length()>0) && (opr2.getText().length()>0))
{
double oper1 = Double.parseDouble(opr1.getText().toString());
double oper2 = Double.parseDouble(opr2.getText().toString());
double result = oper1 + oper2;
txtresult.setText(Double.toString(result));
}
else{
Toast toast= Toast.makeText(MainActivity.this,"Enter The Required Numbers",To
ast.LENGTH_LONG);
toast.show();
}
}
});
//Subtraction
btnsub.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if((opr1.getText().length()>0) && (opr2.getText().length()>0))
{
double oper1 = Double.parseDouble(opr1.getText().toString());
double oper2 = Double.parseDouble(opr2.getText().toString());
double result = oper1 - oper2;
txtresult.setText(Double.toString(result));
}
else{
Toast toast= Toast.makeText(MainActivity.this,"Enter The Required Numbers",To
ast.LENGTH_LONG);
toast.show();
}
}
});
// Multiplication
btnmul.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if((opr1.getText().length()>0) && (opr2.getText().length()>0))
{
double oper1 = Double.parseDouble(opr1.getText().toString());
double oper2 = Double.parseDouble(opr2.getText().toString());
double result = oper1 * oper2;
txtresult.setText(Double.toString(result));
}
else{
Toast toast= Toast.makeText(MainActivity.this,"Enter The Required Numbers",To
ast.LENGTH_LONG);
toast.show();
}
}
});
// Division
btndiv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if((opr1.getText().length()>0) && (opr2.getText().length()>0))
{
double oper1 = Double.parseDouble(opr1.getText().toString());
double oper2 = Double.parseDouble(opr2.getText().toString());
double result = oper1 / oper2;
txtresult.setText(Double.toString(result));
}
else{
Toast toast= Toast.makeText(MainActivity.this,"Enter The Required Numbers",To
ast.LENGTH_LONG);
toast.show();
}
}
});
// Reset Feilds
btnclr.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
opr1.setText("");
opr2.setText("");
txtresult.setText("0.00");
opr1.requestFocus();
}
});

}
}

You might also like