Mad W-22
Mad W-22
(Autonomous) (Autonomous)
(ISO/IEC - 27001 - 2013 Certified) (ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________ __________________________________________________________________________________________________
WINTER – 2022 EXAMINATION c) State how the APK files are built? 2M
Subject Name Mobile Application Development Model Answer Subject Code: 22617
Ans The javac compiler compiles the java source file into the class file. (For each
Important Instructions to examiners: XXXXX The dx tool takes all the class files of your application and generates a single .dex file which step 1/2 M)
1) The answers should be examined by key words and not as word-to-word as given in the model answer is a platform specific tool.
scheme. Then Android Assets Packaging Tool (aapt) handles the packaging process and finally
2) The model answer and the answer written by candidate may vary but the examiner may try to assess the creates an executable file with extension .apk.
understanding level of the candidate. An APK file contains all of a program's code (such as .dex files), resources, assets,
3) The language errors such as grammatical, spelling errors should not be given more Importance (Not certificates, and manifest file.
applicable for subject English and Communication Skills.
4) While assessing figures, examiner may give credit for principal components indicated in the figure. The d) Enlist the elements of UI. 2M
figures drawn by candidate and model answer may vary. The examiner may give credit for any equivalent
figure drawn.
Ans Elements of UI. (1/2 mark
5) Credits may be given step wise for numerical problems. In some cases, the assumed constant values may
for each UI
vary and there may be some difference in the candidate’s answers and model answer.
6) In case of some questions credit may be given by judgement on part of examiner of relevant answer based EditText element,
any 4 UI
on candidate’s understanding. TextView
elements
7) For programming language papers, credit may be given to any other program based on equivalent concept. ListView
expected)
8) As per the policy decision of Maharashtra State Government, teaching in English/Marathi and Bilingual GridView
(English + Marathi) medium is introduced at first year of AICTE diploma Programme from academic year ScrollView
2021-2022. Hence if the students in first year (first and second semesters) write answers in Marathi or ImageView
bilingual language (English +Marathi), the Examiner shall consider the same and assess the answer based
ToggleButton
on matching of concepts with model answer.
CheckBox
Q. Sub Note: As Android programs contain many of the auto generated code statements from IDE, Marking RadioButton
No. Q. while assessing such answers correct logical steps taken to obtain the required output can be Scheme
N. considered. OR
Answer Components of UI
Menu Bar
1 Attempt any FIVE of the following: 10 M
Toolbar
a) Define OHA and state goal of OHA. 2M Navigation Bar
Editor Tabs
Ans The OHA is the group that is in charge of the Android smartphones operating system. It was (Define : 1 Editor
created by Google. The Open Handset Alliance (OHA) is consortium of multiple companies M, Stating Project Explorer
like Samsung, Sony, Intel and many more to provide services and deploy handsets using goal 1 M) Status Bar
android platform.
Tool Buttons
The Open Handset Alliance (OHA) is an association whose goal is to develop open standards e) State the uses of Intent in Android. 2M
for mobile devices, promote innovation in mobile phones and provide a better experience for
consumers at a lower cost. Ans An Intent is a messaging object you can use to request an action from another app component. (1 M for
Intents are used for facilitating communication between components like Activities, Services each use, 2
b) Define Android Virtual Devices (AVD). 2M uses
and Broadcast Receivers.
Ans An Android Virtual Device (AVD) is a configuration that defines the characteristics of an (Define : 2 expected)
Android phone, tablet, Wear OS, Android TV, or Automotive OS device that you want to M ,any valid f) Name any four methods to get location data in android. 2M
simulate in the Android Emulator. The AVD Manager is an interface you can launch from definition
Android Studio that helps you create and manage AVDs. should be
Ans •float distanceTo(Location dest) (1/2 M for
considered)
•float getAccuracy() each
•float getBearing() method,
Page No: 1 | 41 Page No: 2 | 41
for more study material visit www.diplomachakhazana.in
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous) (Autonomous)
(ISO/IEC - 27001 - 2013 Certified) (ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________ __________________________________________________________________________________________________
•double getAltitude() any 4 Android Software, a corresponding SDK also releases with it. In the updated or new version of feature, any
•double getLatitude() methods SDK, some more features are included which are not present in the previous version. Android 4 features
•float getSpeed() expected) SDK consists of some tools which are very essential for the development of Android expected)
•boolean hasAccuracy() Application. These tools provide a smooth flow of the development process from developing
•boolean hasAltitude() and debugging. Android SDK is compatible with all operating systems such as Windows,
•boolean hasBearing() Linux, macOS, etc.
•boolean hasBearing()
1. Android Tool: This tool helps in managing the Android Virtual Device projects as well as
•boolean hasSpeed()
the installed components of the software development kit.
•void reset()
•void setAccuracy(float accuracy) 2. Emulator Tool: It helps us in testing the applications without the need of using the
•void setAltitude(double altitude) application on an actual device.
g) Explain significance of content provider. 2M
3. Dalvik Debug Monitor Server(DDMS): DDMS is very useful for debugging the Android
Ans Content Providers are used to share data between two applications. This can be implemented (1 M for Application.
in two ways: each
significance 4. Android Debug Bridge (ADB): It is a very versatile command-line tool and is helpful for
1. When you want to implement the existing content provider in another application.
, the communication between the developer and the Emulator or the Android device that is
2. When you want to create a new content provider that can share its data with other
connected.
Applications
c) Explain the Android security model. 4M
2. Attempt any THREE of the following: 12 M Ans The Android security model is primarily based on a sandbox and permission mechanism. Each 2 M for
application is running in a specific Dalvik virtual machine with a unique user ID assigned to it, explanation
a) Describe the different features of Android. 4M , 2 M for
which means the application code runs in isolation from the code of all other applications.
Ans User Interface: The user interface of the Android operating system is straight forward, and (1 M for Therefore, one application has not granted access to other applications’ files. explaining
these features make it very user friendly. each permissions
feature, 4 Android application has been signed with a certificate with a private key Know the owner of , any 2
Multiple Language Support: Android supports multiple languages in its operating system and features the application is unique. This allows the author of the application will be identified if needed. permissions
one can change the language very easily based on one’s requirement, the International expected) When an application is installed in the phone is assigned a user ID, thus avoiding it from expected)
languages supported are English, Germany, Chinese, Dutch, French, German, Japanese, affecting it other applications by creating a sandbox for it. This user ID is permanent on which
Korean, Russian, and many more also some native language of India is also Supported Like devices and applications with the same user ID are allowed to run in a single process. This is a
Hindi, Marathi, Gujarati, Punjabi and many more. way to ensure that a malicious application has Cannot access / compromise the data of the
genuine application. It is mandatory for an application to list all the resources it will Access
Multi-tasking: Android provides support to run apps and services in the background with ease during installation. Terms are required of an application, in the installation process should be
which allows the users to use multiple apps at the same time. user-based or interactive Check with the signature of the application.
Connectivity: Android has extensive support to the connectivity and it supports connectivity Declaring and Using Permissions
such as WiFi, Bluetooth, Hotspot, CDMA, GSM, NFC, VOLTE, UBB, VPN, 3G network
band, and 4G Network Band. The purpose of a permission is to protect the privacy of an Android user. Android apps must
request permission to access sensitive user data (such as contacts and SMS), as well as certain
Extensive Application Support: Android have Play store which is used as the major tool to system features (such as camera and internet). Depending on the feature, the system might grant
download and update applications on the operating system, however, one can download the the permission automatically or might prompt the user to approve the request.
installer(often called as APK file) and install it manually, but it is not much recommended as
third party applications could be prone to some security breach in the smartphones. Permissions are divided into several protection levels. The protection level affects whether
runtime permission requests are required. There are three protection levels that affect third-
b) Explain features of Android SDK. 4M party apps: normal, signature, and dangerous permissions.
Ans Android SDK is a collection of libraries and Software Development tools that are essential for (1 M for Normal permissions: Normal permissions cover areas where your app needs to access data or
Developing Android Applications. Whenever Google releases a new version or update of each resources outside the app’s sandbox, but where there’s very little risk to the user’s privacy or
Ans Download the latest version of Android Studio from above URL and launch Android 4 M for
Studio.exe file by double clicking on it. steps
The initial android studio setup screen will open in that click Next to continue for further
steps of environment setup
Now we need to select a required components to setup an android environment. Here
we selected all three components (Android Studio, Android SDK and Android Virtual
Device) and click Next.
Now we need to agree the License agreements to proceed further, click on I Agree
button
Now we need to specify the local machine drive location to install Android Studio and
Android SDK.
After selecting the location path to install required components, click Next.
Now select the start menu folder to create a shortcut for android studio and click Install
Once we click Install button the installation process will start and click Next after
completion of Installation.
After that it will show installation completion wizard in that click Finish to launch
android studio While launching Android Studio it will give you an option to import Activities have a predefined life-cycle methods as follows:
onPause (): Called once another activity gets into the foreground. Always called Step 5: Upload APK to an App Release
before the activity is not visible anymore. Used to release resources or Finally upload your app, by uploading APK file. Before you upload APK, you need to create
save application data. For example you unregister listeners, intent an app release. You need to select the type of release you want to upload your first app version
receivers, unbind from services or remove system service listeners. to. You can choose between an internal test, a closed test, an open test, and a production release.
The first three releases allow you to test out your app among a select group of users before you
onStop (): Called once the activity is no longer visible. Time or CPU intensive shutdown make it go live for everyone to access.
operations, such as writing information to a database should be down in the onStop() method. This is a safer option because you can analyze the test results and optimize or fix your app
This method is guaranteed to be called as accordingly if you need to before rolling it out to all users.
of API 11. Once you create a production release, your uploaded app version will become accessible to
everyone in the countries you choose to distribute it in and click on ‘Create release.’
onDestroy (): called before the activity is destroyed.
d) Explain the steps to deploy app on Google Play Store. 4M Step 6: Provide an Appropriate Content Rating
If you don’t assign a rating to your app, it will be listed as ‘Unrated’. Apps that are ‘Unrated’
Ans Step 1: Create a Developer Account 4 M for all may get removed from Google Play.
Before you can publish any app on Google Play, you need to create a Developer Account. You steps To rate your app, you need to fill out a content rating questionnaire An appropriate content
can easily sign up for one using your existing Google Account. You’ll need to pay a one-time rating will also help you get to the right audience, which will eventually improve your
registration fee of $25 using your international credit or debit card. It can take up to 48 hours engagement rates.
for your registration to be fully processed.
<ProgressBar
4. Attempt any THREE of the following: 12 M android:id="@+id/progressBar"
style="@android:style/Widget.ProgressBar.Horizontal"
a) Explain the fundamentals of Ul design in detail. 4M
android:layout_width="match_parent"
android:layout_height="wrap_content"
Ans 1. Views: 1 M for
android:layout_alignParentLeft="true"
• The basic building block for user interface in Android is a View, which is created from the each android:layout_alignParentTop="true"
View class and occupies a rectangular area on the screen and is responsible for drawing and android:layout_marginLeft="20dp"
event handling. android:layout_marginRight="20dp"
• Views are the base class for all visual interface elements (commonly known as controls or android:layout_marginTop="20dp"
widgets). All user interface UI controls, including the layout classes, are derived from View. android:indeterminate="false"
• A View is an object/widget that draws something on the sreen by the help of user interact. android:max="100"
android:minHeight="50dp"
• Examples of widgets are buttons, text boxes, labels etc.
android:minWidth="200dp"
2. View Groups: android:progress="1" />
• The ViewGroup is a subclass of View and provides invisible container that hold other Views <TextView
or other ViewGroups and define their layout properties. android:id="@+id/textView"
• View groups are extensions of the View class that can contain multiple child Views. In order android:layout_width="wrap_content"
to Extend the ViewGroup class to create compound controls made up of interconnected child android:layout_height="wrap_content"
android:layout_alignLeft="@+id/progressBar"
views.
android:layout_below="@+id/progressBar"/>
• A ViewGroup provides the layout in which we can order the appearance and sequence of </RelativeLayout>
views. Java file:
Examples of ViewGroup are FrmaeLayout, LineourLayout etc. package in.edu.vpt.progressbar;
3. Fragments: import androidx.appcompat.app.AppCompatActivity;
• Fragments represents a portion of user interface in an Activity. Fragments, introduced in import android.os.Bundle;
Android 3.0 which uses API level 11, are used to encapsulate portions of your UI. This import android.os.Handler;
encapsulation makes fragments particularly useful when optimizing our UI layouts for different import android.os.Looper;
screen sizes and creating reusable user interface (UI) elements. import android.widget.ProgressBar;
• Each Fragment includes its own user interface (UI) layout and receives the related input events import android.widget.TextView;
but is tightly bound to the activity into which each must be embedded. Fragments are similar public class MainActivity extends AppCompatActivity {
to UI view controller in iPhone development. private ProgressBar progressBar;
4. Activities: private int progressStatus = 0;
• Activities dictate the UI and handle the user interaction to the smart phone screen. Activities private TextView textView;
represent a single screen that user interact.
• Activities are the Android equivalent of Forms in traditional windows desktop development. @Override
To display a UI we assign a View (Usually a layout or Fragment) to an Activity protected void onCreate(Bundle savedInstanceState) {
b) Write a program to display a rectangular progress bar. 4M super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Ans Xml File: xml file
2M, progressBar = (ProgressBar) findViewById(R.id.progressBar);
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" textView = (TextView) findViewById(R.id.textView);
xmlns:tools="http://schemas.android.com/tools" java file 2 // Start long running operation in a background thread
android:layout_width="match_parent" M new Thread(new Runnable() {
android:layout_height="match_parent" public void run() {
tools:context=".MainActivity">
Page No: 11 | 41 Page No: 12 | 41
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous) (Autonomous)
(ISO/IEC - 27001 - 2013 Certified) (ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________ __________________________________________________________________________________________________
while (progressStatus < 100) { • The application layer runs within the Android run time using the classes and services made
progressStatus += 1; available from the application framework.
new Handler(Looper.getMainLooper()).post(new Runnable() { 2. Application Framework:
public void run() { • The Application Framework provides the classes used to create an Android application. It also
progressBar.setProgress(progressStatus); provides a generic abstraction for hardware access and manages the user interface and
textView.setText(progressStatus+"/"+progressBar.getMax()); application resources.
} • It basically provides the services through which we can create the particular class and make
}); that class helpful for the Applications creation.
try { • The application framework includes services like telephony service, location services,
// Sleep for 200 milliseconds. notification manager, NFC service, view system, etc. which we can use for application
Thread.sleep(200); development as per our requirements.
} catch (InterruptedException e) { 3. Android Runtime:
e.printStackTrace(); • Android Runtime environment is an important part of Android rather than an internal part and
} it contains a components like core libraries and the Dalvik virtual machine.
} • The Android run time is the engine that powers our applications along with the libraries and
} it forms the basis for the application framework.
}).start(); (i) Dalvik Virtual Machine (DVM) is a register-based virtual machine like Java Virtual
} Machine (JVM).
} It is specially designed and optimized for android to ensure that a device can run multiple
c) Explain Android system architecture in detail. 4M instances efficiently. It relies on the Linux kernel for threading and low-level memory
management.
Ans Diagram
(ii) The core libraries in android runtime will enable us to implement an android applications
2 M, using standard JAVA programming language.
Explanation
4. Platform Libraries:
2M • The Platform Libraries includes various C/C++ core libraries and Java based libraries such as
SSL, libc, Graphics, SQLite, Webkit, Media, Surface Manger, OpenGL etc. to provide a
support for android development.
5. Linux Kernel:
• Linux Kernel is a bottom layer and heart of the android architecture. It is heart of Android
architecture that exists at the root of android architecture and contains all the low-level device
drivers for the various hardware components of an Android device.
• Linux Kernel is responsible for device drivers, power management, memory management,
device management and resource access. It manage all the drivers such as display drivers,
camera drivers, Bluetooth drivers, audio drivers, memory drivers, etc. which are mainly
required for the android device during the runtime.
• The Linux Kernel will provide an abstraction layer between the device hardware and the
remainder of the stack. It is responsible for memory management, power management, device
management, resource access, etc.
d) Explain the procedure of Geo-coding and reverse Geo-coding. 4M
1. Applications:
• The top layer of android architecture is Applications. The native and third party applications Ans Geo-Coding: geocoding 2
like Contacts, Email, Music, Gallery, Clock, Games, etc. whatever we will build those will be • If we know the latitude and longitude of a location, we can find out its address using a process M
installed on this layer only. known as Geocoding. Google Maps in Android supports this via the Geocoder class.
} <EditText
} android:layout_width="fill_parent"
6. Attempt any TWO of the following: 12 M android:layout_height="wrap_content"
android:hint="Mobile No."
android:id="@+id/editmobile"
android:layout_below="@+id/editname"/>
Page No: 27 | 41 Page No: 28 | 41
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous) (Autonomous)
(ISO/IEC - 27001 - 2013 Certified) (ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________ __________________________________________________________________________________________________
<Button
<EditText android:text="Search Data"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="Address" android:layout_below="@+id/editsearchid"
android:lines="3" android:layout_centerHorizontal="true"
android:id="@+id/editaddress" android:id="@+id/button1" />
android:layout_below="@+id/editmobile"/> </RelativeLayout>
<EditText MainActivity.java
android:layout_width="fill_parent" package in.msbte.database;
android:layout_height="wrap_content" import androidx.appcompat.app.AppCompatActivity;
android:hint="Pin Code" import android.content.Context;
android:id="@+id/editpincode" import android.database.Cursor;
android:layout_below="@+id/editaddress"/> import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
<Button import android.view.View;
android:text="Insert Data" import android.widget.Button;
android:layout_width="fill_parent" import android.widget.EditText;
android:layout_height="wrap_content" import android.widget.Toast;
android:layout_below="@+id/editpincode"
android:layout_centerHorizontal="true" public class MainActivity extends AppCompatActivity {
android:id="@+id/button" /> SQLiteDatabase sqLiteDatabaseObj;
EditText editTextID, editTextName, editMobileNo, editAddress, editPincode,
<TextView editSearchid;
android:text="Search Customer Details" String cid, cname, cmobile, caddress, cpincode, sql_query, sid;
android:layout_width="wrap_content" Button EnterData, SearchData;
android:layout_height="wrap_content"
android:layout_marginTop="30dp" @Override
android:layout_centerHorizontal="true" protected void onCreate(Bundle savedInstanceState) {
android:id="@+id/textView1" super.onCreate(savedInstanceState);
android:gravity="center" setContentView(R.layout.activity_main);
android:textSize="20dp" EnterData = (Button)findViewById(R.id.button);
android:layout_below="@+id/button" SearchData = (Button)findViewById(R.id.button1);
android:textColor="#000000"/> editTextID = (EditText)findViewById(R.id.editid);
editTextName = (EditText)findViewById(R.id.editname);
<EditText editMobileNo = (EditText)findViewById(R.id.editmobile);
android:layout_width="fill_parent" editAddress = (EditText)findViewById(R.id.editaddress);
android:layout_height="wrap_content" editPincode = (EditText)findViewById(R.id.editpincode);
android:hint="Enter ID" editSearchid = (EditText)findViewById(R.id.editsearchid);
android:id="@+id/editsearchid"
android:layout_below="@+id/textView1"/> EnterData.setOnClickListener(new View.OnClickListener() {
@Override
Page No: 29 | 41 Page No: 30 | 41
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous) (Autonomous)
(ISO/IEC - 27001 - 2013 Certified) (ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________ __________________________________________________________________________________________________
public void onClick(View view) { Ans AndroidManifest.xml Manifest
sqLiteDatabaseObj = openOrCreateDatabase("AndroidJSonDataBase", file :2M
<?xml version="1.0" encoding="utf-8"?>
Context.MODE_PRIVATE, null); Java File :
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
sqLiteDatabaseObj.execSQL("CREATE TABLE IF NOT EXISTS package="com.example.msbte.google_map_currentlocationroute"> 4M
AndroidJSonTable(id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, cid
VARCHAR, name VARCHAR, mobile VARCHAR, address VARCHAR, pincode <uses-permission android:name="android.permission.INTERNET" />
VARCHAR);"); <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
cid = editTextID.getText().toString(); <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"
cname = editTextName.getText().toString() ; />
<application
cmobile = editMobileNo.getText().toString();
android:allowBackup="true"
caddress = editAddress.getText().toString(); android:icon="@mipmap/ic_launcher"
cpincode = editPincode.getText().toString(); android:label="@string/app_name"
sql_query = "INSERT INTO AndroidJSonTable (cid, name, mobile, address, android:roundIcon="@mipmap/ic_launcher_round"
pincode) VALUES('"+cid+"', '"+cname+"', '"+cmobile+"', '"+caddress+"', '"+cpincode+"');"; android:supportsRtl="true"
sqLiteDatabaseObj.execSQL(sql_query); android:theme="@style/AppTheme">
Toast.makeText(getApplicationContext(), "Data Inserted Successfully",
<meta-data
Toast.LENGTH_LONG).show();
android:name="com.google.android.gms.version"
} android:value="@integer/google_play_services_version" />
}); <meta-data
android:name="com.google.android.geo.API_KEY"
SearchData.setOnClickListener(new View.OnClickListener() { android:value="@string/google_maps_key" />
@Override
public void onClick(View view) { <activity android:name=".MainActivity">
<intent-filter>
sid = editSearchid.getText().toString(); <action android:name="android.intent.action.MAIN" />
Cursor cursor = sqLiteDatabaseObj.rawQuery( "select * from AndroidJSonTable
where cid="+sid+"", null ); <category android:name="android.intent.category.LAUNCHER" />
StringBuffer buffer= new StringBuffer(); </intent-filter>
while (cursor.moveToNext()) </activity>
{ </application>
</manifest>
String cid =cursor.getString(1);
String name =cursor.getString(2); MainActivity.java
String mob =cursor.getString(3);
String addr =cursor.getString(4); import android.Manifest;
String pcode =cursor.getString(5); import android.content.DialogInterface;
buffer.append(cid+ " " + name + " " + mob +" " + addr +" " + pcode +" import android.content.Intent;
\n"); import android.content.pm.PackageManager;
import android.location.Location;
Toast.makeText(getApplicationContext(), buffer,
import android.net.Uri;
Toast.LENGTH_LONG).show(); import android.provider.Settings;
} }); } } import android.support.v4.app.ActivityCompat;
b) Write a program to find the direction from user's current location to MSBTE, 6M import android.support.v7.app.AlertDialog;
Bandra. (Write only Java and manitest file). import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
(Note : Any other relevant logic to get the required output can also be considered.) import android.util.Log;
<EditText <Button
android:id="@+id/num2" android:id="@+id/mul"
android:layout_below="@+id/num1" android:layout_below="@id/result"
android:hint="Enter Number 2" android:layout_toRightOf="@id/div"
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:inputType="number" /> android:layout_marginLeft="10dp"
android:text="x"/>
<TextView </RelativeLayout>
android:id="@+id/result"
android:layout_below="@+id/num2" MainActivity.java
android:layout_width="match_parent" package in.msbte.calculator;
android:layout_height="wrap_content" import androidx.appcompat.app.AppCompatActivity;
android:layout_marginTop="20dp" import android.os.Bundle;
android:layout_marginBottom="20dp" import android.view.View;
android:text="Result" /> import android.widget.Button;
import android.widget.EditText;
<Button import android.widget.TextView;
android:id="@+id/sum" public class MainActivity extends AppCompatActivity {
android:layout_below="@id/result" public EditText e1, e2;
android:layout_width="wrap_content" Button add, sub , mul, div;
android:layout_height="wrap_content" TextView t1;
android:layout_marginLeft="10dp" int num1, num2;
android:text="+" /> @Override
protected void onCreate(Bundle savedInstanceState) {
<Button super.onCreate(savedInstanceState);
android:id="@+id/sub" setContentView(R.layout.activity_main);
android:layout_below="@id/result" e1 = (EditText) findViewById(R.id.num1);
android:layout_toRightOf="@id/sum" e2 = (EditText) findViewById(R.id.num2);
android:layout_width="wrap_content" t1 = (TextView) findViewById(R.id.result);
android:layout_height="wrap_content" add = (Button) findViewById(R.id.sum);
android:layout_marginLeft="10dp" mul = (Button) findViewById(R.id.mul);
android:text="-" /> div = (Button) findViewById(R.id.div);
sub = (Button) findViewById(R.id.sub);
<Button add.setOnClickListener(new View.OnClickListener() {
Page No: 39 | 41 Page No: 40 | 41
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
@Override
public void onClick(View view) {
num1 = Integer.parseInt(e1.getText().toString());
num2 = Integer.parseInt(e2.getText().toString());
int sum = num1 + num2;
t1.setText(Integer.toString(sum));
}
});
sub.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
num1 = Integer.parseInt(e1.getText().toString());
num2 = Integer.parseInt(e2.getText().toString());
int sum = num1 - num2;
t1.setText(Integer.toString(sum));
}
});
mul.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
num1 = Integer.parseInt(e1.getText().toString());
num2 = Integer.parseInt(e2.getText().toString());
int sum = num1 * num2;
t1.setText(Integer.toString(sum));
}
});
div.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
num1 = Integer.parseInt(e1.getText().toString());
num2 = Integer.parseInt(e2.getText().toString());
int sum = num1 / num2;
t1.setText(Integer.toString(sum));
}
});
}
}
Page No: 41 | 41