Mobile Application Development
Regulation – R22
Lab manual for the Academic Year
(2023-2024)
III B. Tech II Semester
DEPARTMENT OF
INFORMATION TECHNOLOGY
Vadlamudi, 522 213, AP, India
Name of the Faculty: [Link] sultana shaik,
Assistant Professor, Dept. of IT
MOBILE APPLICATION DEVELOPMENT LAB MANNUAL Page 1
Manual Structure
This manual is organized in such a way that the students can directly use it in the
laboratory. Each laboratory exercise comprises of
1. Statement of the problem
2. XML file
4. Java file
5. Result
Scheme of evaluation of laboratory
The weight age for continuous in semester performance evaluation shall be 50 marks
and the end semester performance shall be 50 marks.
The assessment for in semester performance will be based on the student attendance,
regular work in the experiments, performance in viva-voce, result analysis of each
experiment, quality of reports submitted regularly and in semester examination.
For in semester examination
Activity Marks
1. Attendance 5
2. Performing experiment 10
3. Analysis of results and interpretation 5
4. Punctual submission of quality records 10
5. Laboratory in semester test 20
Total 50
For End semester examination
Activity Marks
1. Design /Mathematical model 20
2. Implementation 20
3. Viva-voce 10
Total 50
MOBILE APPLICATION DEVELOPMENT LAB MANNUAL Page 2
Objective of Laboratory
1. To make students to implement different application programs by using the Activities,
Intents, Dialog Objects and Fragments by using the Android.
2. At end of the course the student will be
Familiar with understanding and Linking of activities using intents.
Familiar with different Layouts such as Linear, absolute, Relative, Frame and
Scroll Views.
Master analysing problems and writing program solutions to problems using the
above design techniques.
Recommended System/ Software Requirements
Intel based desktop PC with Java
Android Studio
MOBILE APPLICATION DEVELOPMENT LAB MANNUAL Page 3
Experiments List
1. Installation of Android studio, its required tools and Android Virtual Device (Emulator).
2. a) Displaying the welcome message in AVD.
b) Design an android application to display name, class, college, address etc. of a
student.
3. a) Creating a basic Activity and applying themes, styles to it.
b) Create an application to understand the Life Cycle of an Activity.
c) Create an android application which display three buttons on main activity named
RED, GREEN and BLUE. The background colour of the activity should be changed to
appropriate colour when the user selects any of these buttons.
4. a) Displaying various types of Dialog objects.
b) Develop a simple application showing a dialog box.
5. Linking activities with Intents.
a) Create an application with Explicit Intents
b) Create an application of Calling Built-In apps using Intents (Implicit Intents)
c) Design an android application login form whenever user select login in the another
displays the message as “WELCOME TO VIGNAN’S UNIVERSITY”
6. a) Passing data using Intent object.
b)Develop an application of Basic Calculator app.
7. a) Usage of Fragments and adding them dynamically to the application.
b) Usage of Fragments and adding them dynamically to the application.
8. a) Communication between fragments.
b) Develop an application of BMI
9. Creating various layouts.
a) Linear Layout
b) Absolute Layout
c) Table Layout
d) Relative Layout
e) Frame Layout
f) Scroll View
g) Design an application which contains some buttons named as relative layout, Linear
layout, Table Layout…etc. Whenever the user selects the corresponding button it
will opens a new activity which are designed according to the name displayed in the
button.
10. a) Displaying Action bar.
b) Design an Action bar which is similar to WHATS APP.
11. a) Handling view events.
b) Create an application of scoreboard app
12. Create an application by following all the conditions
Registration form by including all basic views,
Display the dialog box as “Please verify all the details once again”
Successfully register, Open the activity is designed with fragments
Navigate to another activity present in different application.
Develop the action bar for that activity.
MOBILE APPLICATION DEVELOPMENT LAB MANNUAL Page 4
EXPERIMENT - 1
AIM: a) Installation of Android studio, its required tools and Android Virtual
Device (Emulator).
Android Studio is one of the best and most popular IDE for development of Android
application which is released by IntelliJ IDEA. Android studio has rich functionalists
and easy to work. Android studio has great and awesome user interface, it is also smart
with coding and will save your time.
Android programming is Java based programming so it requires JDK & JRE
environment. You must have to install JDK & JRE for working with android. After
installing JDK and JRE you need to configure Environment variables on your
computer. Environment variables let to provide some specific path for android. There
will be JDK/bin or JDK only. After installing JDK & JRE and configuring
environment variables, the next step will be installation of SDK (Software
Development Kit). This is another important component for android programming. If
you are thinking to develop android apps, then you must install SDK on your
computer.
Installing Android Studio on Windows
To download Android Studio form the website [Link] There you
will see android studio download button.
After downloading android studio, follow below steps to install android studio on your
computer.
Step1: First unzip the downloaded android studio file, open it and wait for few
seconds, it will take some time to load on your screen.
MOBILE APPLICATION DEVELOPMENT LAB MANNUAL Page 5
Step2: After that the window will appear on your screen, where it will show you
welcome to android studio setup. Go for "Next"
Step3: Now choose what you want to install, all are most important component in
android programming. Go for "Next"
Step4: Go for "I Agree", It's for integrating SDK, it will confirm SDK installation.
MOBILE APPLICATION DEVELOPMENT LAB MANNUAL Page 6
Step5: Go for "I Agree", It's for Haxm installation
Step6: Now choose the location for Android Studio and [Link] for "Next"
Step7: Here you need to define the size of android emulator processor. You can define
up to 2GB and more than that, depends on your RAM capacity. The size will be
determined through Haxm. This will help your android studio to run faster.
MOBILE APPLICATION DEVELOPMENT LAB MANNUAL Page 7
Step8: Now choose setting for shortcut of android studio on your computer.
Step9: After that it will take lots of time to copy all the files to the storage location you
have selected before
MOBILE APPLICATION DEVELOPMENT LAB MANNUAL Page 8
MOBILE APPLICATION DEVELOPMENT LAB MANNUAL Page 9
EXPERIMENT – 2
AIM: a) Displaying the welcome message in AVD.
Android Studio is one of the best IDE (Integrated Development Environment) for
Android Developers with rich functionality and control mechanism. It was announced
on 2013 and today it is one of the most popular IDE in the world for android
development purpose.
In this we will learn how to create new project on android studio.
Step1: First of all you need to start your Android Studio. Then it will show you the
default start window on your screen, where you can see various options.
In this window you have to click on Start a new Android Studio project, that will let
you create new project on android studio.
Step2: After clicking on new project will get another window on your screen which
will ask for project information or configuration.
MOBILE APPLICATION DEVELOPMENT LAB MANNUAL Page 10
As you can see on the above windows, you need to put Application Name, Application
Name: Without Space, Capitalized letter format.
You must write your company name like we have [Link], or
[Link], [Link] etc.
Package Name: Package naming convention is reverse notation as you write company
name it will automatically change the package name in the form of reverse notation.
Project Location: You must select appropriate location for your project. That might be
default location of C drive or you can select another drive location to save your special
project.
Step3: After doing all the above tasks you must have to choose platform where you
want to run your android application. Run able factors for your project. You can
choose as per your need.
Step4: Now here you have to choose the activity where you will get java classes and
xml files for designing and coding purpose. You can even choose no activity format. If
you choose that there will be no auto generated codes on your project. If you select
Blank Activity, you will get auto generated codes and that will save lots of time.
MOBILE APPLICATION DEVELOPMENT LAB MANNUAL Page 11
Step5: In this you have to select layout name, activity name etc...
Than after you just have to click on Finish button. Now it will take little time to create
your new project on Android Studio
Displaying the welcome message in AVD:
Step1: create a new project
Step 2: open a [Link] file
XMLfile (activity_main.xml)
<?xml version="1.0" encoding="utf-8"?>
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="32dp"
android:text="WELCOME to Mobile Application Development Lab"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</[Link]>
Step 3: open the java file
MOBILE APPLICATION DEVELOPMENT LAB MANNUAL Page 12
[Link]
package [Link].exp1;
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
}
}
step 4: Debug and run the application.
Exercise Program: b) Design an android application to display name, class, college,
address etc. of a student.
MOBILE APPLICATION DEVELOPMENT LAB MANNUAL Page 13
EXPERIMENT – 3
AIM: a) How the life cycle of an activity is executed.
Step 1: open the new project
Java file([Link])
package [Link].myactivity101;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
String tag=”Life cycle”;
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
Log.d(tag,"onCreate() invoked");
}
protected void onStart() {
[Link]();
Log.d(tag,"onStart() invoked");
}
protected void onResume() {
[Link]();
Log.d(tag,"onResume() invoked");
}
protected void onPause() {
[Link]();
Log.d(tag,"onPause() invoked");
}
protected void onStop() {
[Link]();
Log.d(tag,"onstop() invoked");
}
protected void onRestart() {
[Link]();
Log.d(tag,"onRestart() invoked");
}
protected void onDestroy() {
[Link]();
Log.d(tag,"onDestroy() invoked");
}
}
(activity_main.xml)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="[Link]
xmlns:app="[Link]
MOBILE APPLICATION DEVELOPMENT LAB MANNUAL Page 14
xmlns:tools="[Link]
android:layout_width="match_parent"
android:orientation=”vertical”
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:text="Button" />
</[Link]>
Output:
When Activity is loaded , the following is displayed in the LogCat window.
D/Lifecycle : onCreate() invoked
D/Lifecycle : onStart() invoked
D/Lifecycle : onResume() invoked
If you click back button on the android emulator, the following is printed.
D/Lifecycle : onPause() invoked
D/Lifecycle : onStop() invoked
D/Lifecycle : onDestroy() invoked
Click home button and hold it there. Click the Activities icon and observe the
following.
D/Lifecycle : onCreate() invoked
D/Lifecycle : onStart() invoked
D/Lifecycle : onResume() invoked
Click the phone button on the android emulator so that the activity is pushed to the
background Observe the output in Logcat.
D/Lifecycle : onPause() invoked
D/Lifecycle : onStop() invoked
When closing the activity it display the following
D/Lifecycle : onRestart() invoked
D/Lifecycle : onStart() invoked
D/Lifecycle : onResume() invoked
MOBILE APPLICATION DEVELOPMENT LAB MANNUAL Page 15
b) Creating a basic Activity and applying a themes, styles to it.
In the manifest file apply attribute named as android:theme.
Manifestfile
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="[Link]
package="[Link].s1">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity"
android:theme="@style/[Link]">
<intent-filter>
<action android:name="[Link]" />
<category android:name="[Link]" />
</intent-filter>
</activity>
</application>
[Link] file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
adroid:orientation="vertical"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!”
android:textColor="@android:color/holo_blue_bright"
android:textStyle="bold” />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/holo_red_dark"
android:textStyle="bold"
android:text="This is Andorid studio"/>
MOBILE APPLICATION DEVELOPMENT LAB MANNUAL Page 16
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/holo_green_dark"
android:textStyle="italic"
android:text="WELCOME" />
</LinearLayout >
[Link]
package [Link].s1;
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
}
}
Exercise Program: c) Create an android application which display three buttons on main
activity named RED, GREEN and BLUE. The background colour of the activity should be
changed to appropriate colour when the user selects any of these buttons.
MOBILE APPLICATION DEVELOPMENT LAB MANNUAL Page 17
EXPERIMENT – 4
AIM:4a) Displaying a dialog types of dialog objects
[Link] file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="[Link]
xmlns:tools="[Link]
xmlns:app="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="close app" />
</LinearLayout>
[Link]
package [Link].sd1;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
Button closeButton;
[Link] builder;
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
closeButton = (Button) findViewById([Link]);
builder = new [Link](this);
[Link](new [Link]() {
public void onClick(View v) {
[Link]("Do you want to close the application");
[Link](false);
[Link]("yes", new [Link]() {
MOBILE APPLICATION DEVELOPMENT LAB MANNUAL Page 18
public void onClick(DialogInterface dialog, int which) {
finish();
[Link](getApplicationContext(), "",Toast.LENGTH_SHORT).show();
}
});
[Link]("NO", new [Link]() {
public void onClick(DialogInterface dialog, int which) {
[Link]();
[Link](getApplicationContext(),"you choose the no action in the
alert box",Toast.LENGTH_SHORT).show();
}
});
AlertDialog alert =[Link]();
[Link]("AlertDialogExample");
[Link]();
}
});
}
}
Exercise Program: b) Develop a simple application showing a dialog box.
MOBILE APPLICATION DEVELOPMENT LAB MANNUAL Page 19
EXPERIMENT – 5
AIM: a) Linking of Activities with Intents.
Implicit Intents:
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Open URL"
android:onClick="openURL" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="call"
android:onClick="makeacall" />
</LinearLayout>
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
}
public void openURL(View view)
{
Uri u= [Link]("[Link]
Intent i=new Intent(Intent.ACTION_VIEW,u);
startActivity(i);
MOBILE APPLICATION DEVELOPMENT LAB MANNUAL Page 20
}
public void makeacall(View view)
{
Uri u=[Link]("[Link]
Intent i=new Intent(Intent.ACTION_DIAL,u);
startActivity(i);
}
}
OUTPUT:
b)Linking of Activities with Explicit Intents:
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:id="@+id/btn1"
MOBILE APPLICATION DEVELOPMENT LAB MANNUAL Page 21
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Display Second Activity"
android:onClick="onClick" />
</LinearLayout>
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
Button B;
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
B = (Button) findViewById([Link].btn1);
}
public void onClick(View view) {
Intent i = new Intent([Link], [Link]);
startActivity(i);
}
}
activity_second.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".secondA">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome to Second Activity"
/>
</LinearLayout>
[Link]
package [Link];
import [Link];
import [Link];
public class secondA extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
MOBILE APPLICATION DEVELOPMENT LAB MANNUAL Page 22
[Link](savedInstanceState);
setContentView([Link].activity_second);
}
}
output:
Exercise Program: c) Design an android application login form whenever user select login
in the another displays the message as “WELCOME TO VIGNAN’S UNIVERSITY”
MOBILE APPLICATION DEVELOPMENT LAB MANNUAL Page 23
EXPERIMENT – 6
AIM: a) Passing data using intent object.
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="display secongActivity"
android:onClick="showSecond"/>
</LinearLayout>
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
int request_Value=1;
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
}
public void showSecond(View view) {
Intent i1 = new Intent(this, [Link]);
startActivityForResult(i1, request_Value);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
[Link](requestCode, resultCode, data);
if (requestCode == requestCode){
if (resultCode == RESULT_OK) {
[Link](this,[Link]().toString(), Toast.LENGTH_SHORT).show();
}
}
MOBILE APPLICATION DEVELOPMENT LAB MANNUAL Page 24
}
}
activity_second.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".second">
<TextView
android:id="@+id/t1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Enter your name"/>
<EditText
android:id="@+id/e1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/b1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="ok"
android:onClick="meth1"/>
</LinearLayout>
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class second extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_second);
}
public void meth1(View view){
Intent data=new Intent();
EditText ed=(EditText)findViewById([Link].e1);
[Link]([Link]([Link]().toString()));
setResult(RESULT_OK,data);
finish();
}
}
MOBILE APPLICATION DEVELOPMENT LAB MANNUAL Page 25
output:
Exercise Program: b) Develop an application of basic calculator app.
MOBILE APPLICATION DEVELOPMENT LAB MANNUAL Page 26
EXPERIMENT – 7
AIM: a) Usage of Fragments and adding them Statically to the application.
[Link]
<?xml version=”1.0” encoding=”utf-8”?>
<LinearLayout
xmlns:android=”[Link]
android:orientation=”vertical”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:background=”#00FF00” >
<TextView
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”This is fragment #1”
android:textColor=”#000000”
android:textSize=”25sp” />
</LinearLayout>
[Link]
<?xml version=”1.0” encoding=”utf-8”?>
<LinearLayout
xmlns:android=”[Link]
android:orientation=”vertical”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:background=”#FFFE00”>
<TextView
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”This is fragment #2”
android:textColor=”#000000”
android:textSize=”25sp” />
</LinearLayout>
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class Fragment1 extends Fragment {
public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle
savedInstanceState) {
return [Link]([Link].fragment1, container, false);
}
MOBILE APPLICATION DEVELOPMENT LAB MANNUAL Page 27
}
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class Fragment2 extends Fragment {
public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle
savedInstanceState) {
return [Link]([Link].fragment2, container, false);
}
}
Main_Activity.xml
<?xml version=”1.0” encoding=”utf-8”?>
<LinearLayout
xmlns:android=”[Link]
android:orientation=”horizontal”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”>
<Fragment
android:name=”[Link].Fragment1”
android:id=”@+id/Fragment1”
android:layout_width=”1”
android:layout_width=”0px”
android:layout_height=”match_parent”/>
<Fragment
android:name=”[Link].Fragment2”
android:id=”@+id/Fragment2”
android:layout_width=”1”
android:layout_width=”0px”
android:layout_height=”match_parent”/>
</LinearLayout>
OUTPUT:
MOBILE APPLICATION DEVELOPMENT LAB MANNUAL Page 28
AIM: b) Usage of Fragments and adding them dynamically to the application.
[Link]
<?xml version=”1.0” encoding=”utf-8”?>
<LinearLayout
xmlns:android=”[Link]
android:orientation=”vertical”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:background=”#00FF00” >
<TextView
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”This is fragment #1”
android:textColor=”#000000”
android:textSize=”25sp” />
</LinearLayout>
[Link]
<?xml version=”1.0” encoding=”utf-8”?>
<LinearLayout
xmlns:android=”[Link]
android:orientation=”vertical”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:background=”#FFFE00”>
<TextView
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”This is fragment #2”
android:textColor=”#000000”
android:textSize=”25sp” />
</LinearLayout>
[Link]
package [Link];
import [Link];
MOBILE APPLICATION DEVELOPMENT LAB MANNUAL Page 29
import [Link];
import [Link];
import [Link];
import [Link];
public class Fragment1 extends Fragment {
public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle
savedInstanceState) {
return [Link]([Link].fragment1, container, false);
}
}
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class Fragment2 extends Fragment {
public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle
savedInstanceState) {
return [Link]([Link].fragment2, container, false);
}
}
Main_Activity.java
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class FragmentsActivity extends Activity {
public void onCreate(Bundle savedInstanceState)
{
[Link](savedInstanceState);
FragmentManager fm = getFragmentManager();
FragmentTransaction ft =[Link]();
WindowManager wm = getWindowManager();
Display d = [Link]();
if ([Link]() > [Link]())
{
Fragment1 fragment1 = new Fragment1();
[Link]([Link], fragment1);
}
else
{
Fragment2 fragment2 = new Fragment2();
[Link]([Link], fragment2);
MOBILE APPLICATION DEVELOPMENT LAB MANNUAL Page 30
}
[Link]();
}
}
OUTPUT:
EXPERIMENT – 8
AIM: Communication between fragments
[Link]
<?xml version=”1.0” encoding=”utf-8”?>
<LinearLayout
xmlns:android=”[Link]
android:orientation=”vertical”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:background=”#00FF00” >
<TextView
android:id=”@+id/lblFragment1”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”This is fragment #1”
android:textColor=”#000000”
android:textSize=”25sp” />
</LinearLayout>
[Link]
<?xml version=”1.0” encoding=”utf-8”?>
<LinearLayout
xmlns:android=”[Link]
android:orientation=”vertical”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:background=”#FFFE00” >
<TextView
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”This is fragment #2”
android:textColor=”#000000”
android:textSize=”25sp” />
<Button
android:id=”@+id/btnGetText”
android:layout_width=”wrap_content”
MOBILE APPLICATION DEVELOPMENT LAB MANNUAL Page 31
android:layout_height=”wrap_content”
android:text=”Get text in Fragment #1”
android:textColor=”#000000”
android:onClick=”onClick” />
</LinearLayout>
[Link]
<?xml version=”1.0” encoding=”utf-8”?>
<LinearLayout xmlns:android=[Link]
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:orientation=”horizontal” >
<fragment
android:name=”[Link].Fragment1”
android:id=”@+id/fragment1”
android:layout_weight=”1”
android:layout_width=”0px”
android:layout_height=”match_parent” />
<fragment
android:name=”[Link].Fragment2”
android:id=”@+id/fragment2”
android:layout_weight=”1”
android:layout_width=”0px”
android:layout_height=”match_parent” />
</LinearLayout>
[Link]
public class FragmentsActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link]);
}
}
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class Fragment2 extends Fragment {
public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle
savedInstanceState) {
return [Link]([Link].fragment2, container, false);
}
public void onStart() {
MOBILE APPLICATION DEVELOPMENT LAB MANNUAL Page 32
[Link]();
Button btnGetText = (Button)getActivity().findViewById([Link]);
[Link](new [Link]() {
public void onClick(View v) {
TextView lbl = (TextView)getActivity().findViewById ([Link].lblFragment1);
[Link](getActivity(), [Link](),Toast.LENGTH_SHORT). show();
}
});
}
}
Output:
Exercise Program: b) Develop an application of BMI calculation.
MOBILE APPLICATION DEVELOPMENT LAB MANNUAL Page 33
EXPERIMENT – 9
AIM: Creating various layouts.
a) Linear Layout
<?xml version=”1.0” encoding=”utf-8”?>
<LinearLayout
xmlns:android=”[Link]
android:orientation=”vertical”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”>
<TextView
android:layout_width=”105dp”
android:layout_height=”wrap_content”
android:text=”@string/hello” />
<Button
android:layout_width=”160dp”
android:layout_height=”wrap_content”
android:text=”Button”
android:layout_gravity=”right”
android:layout_weight=”0.2” />
<EditText
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:textSize=”18sp”
android:layout_weight=”0.8” />
</LinearLayout>
b) Absolute Layout
<?xml version=”1.0” encoding=”utf-8”?>
<AbsoluteLayout
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
xmlns:android=”[Link]
<Button
MOBILE APPLICATION DEVELOPMENT LAB MANNUAL Page 34
android:layout_width=”188dp”
android:layout_height=”wrap_content”
android:text=”Button”
android:layout_x=”126px”
android:layout_y=”361px”/>
<Button
android:layout_width=”113dp”
android:layout_height=”wrap_content”
android:text=”Button”
android:layout_x=”12px”
android:layout_y=”361px”/>
</AbsoluteLayout>
c) Table Layout
<?xml version=”1.0” encoding=”utf-8”?>
<TableLayout
xmlns:android=”[Link]
android:layout_height=”fill_parent”
android:layout_width=”fill_parent”>
<TableRow>
<TextView
android:text=”User Name:”
android:width =”120px”/>
<EditText
android:id=”@+id/txtUserName”
android:width=”200px” />
</TableRow>
<TableRow>
<TextView
android:text=”Password:”/>
<EditText
android:id=”@+id/txtPassword”
android:password=”true”/>
</TableRow>
<TableRow>
<TextView />
<CheckBox
android:id=”@+id/chkRememberPassword”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”Remember Password”/>
</TableRow>
<TableRow>
<Button
android:id=”@+id/buttonSignIn”
android:text=”Log In” />
</TableRow>
</TableLayout>
MOBILE APPLICATION DEVELOPMENT LAB MANNUAL Page 35
<?xml version=”1.0” encoding=”utf-8”?>
<RelativeLayout
android:id=”@+id/RLayout”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
xmlns:android=”[Link]
<TextView
android:id=”@+id/lblComments”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”Comments”
android:layout_alignParentTop=”true”
android:layout_alignParentLeft=”true”/>
<EditText
android:id=”@+id/txtComments”
android:layout_width=”fill_parent”
android:layout_height=”170px”
android:textSize=”18sp”
android:layout_alignLeft=”@+id/lblComments”
android:layout_below=”@+id/lblComments”
android:layout_centerHorizontal=”true”/>
<Button
android:id=”@+id/btnSave”
android:layout_width=”125px”
android:layout_height=”wrap_content”
android:text=”Save”
android:layout_below=”@+id/txtComments”
android:layout_alignRight=”@+id/txtComments”/>
<Button
android:id=”@+id/btnCancel”
android:layout_width=”124px”
android:layout_height=”wrap_content”
android:text=”Cancel”
android:layout_below=”@+id/txtComments”
android:layout_alignLeft=”@+id/txtComments”/>
</RelativeLayout>
d) Frame Layout
<?xmlversion=”1.0”encoding=”utf-8”?>
<RelativeLayout
android:id=”@+id/Rlayout”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
xmlns:android=”[Link]
d”>
<TextView
android:id=”@+id/lblcomments”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
MOBILE APPLICATION DEVELOPMENT LAB MANNUAL Page 36
android:text=”Hello, Android”
android:layout_alignParentTop=”true”
android:layout_alignParentLeft=”true”/>
<FrameLayout
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_alignLeft=”@+id/lblComments”
android:layout_below=”@+id/lblComments”
android:layout_centerHorizontal=”true”>
<ImageView
android:src = “@drawable/ookii”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”/>
<Button
android:layout_width=”124dp”
android:layout_height=”wrap_content”
android:text=”Print Picture” />
</FrameLayout>
e) Scroll view
<?xmlversion=”1.0”encoding=”utf-8”?>
<ScrollView
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
xmlns:android=”[Link]
<LinearLayout
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:orientation=”vertical”>
<Button
android:id=”@+id/button1”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”Button 1”/>
<Button
android:id=”@+id/button2”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”Button 2”/>
<Button
android:id=”@+id/button3”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”Button 3”/>
<EditText
android:id=”@+id/txt”
android:layout_width=”fill_parent”
android:layout_height=”300px”/>
<Button
android:id=”@+id/button4”
MOBILE APPLICATION DEVELOPMENT LAB MANNUAL Page 37
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”Button 4”/>
<Button
android:id=”@+id/button5”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”Button 5”/>
</LinearLayout>
</ScrollView>
Exercise Program: f) Design an application which contains some buttons named as relative
layout, Linear layout, Table Layout…etc. Whenever the user selects the corresponding
button it will opens a new activity which are designed according to the name displayed in
the button.
MOBILE APPLICATION DEVELOPMENT LAB MANNUAL Page 38
EXPERIMENT – 10
AIM: Displaying Action bar.
Step1: Create a new project and name as exp1 and then select the Empty Activity, and click
finish.
Step 2: open the xml file and write the code.
[Link]
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome to Mobile Application Development lab"/>
</LinearLayout>
Step3: In java create a method onCreateOptionsMenu(). For this one goto res and create a
folder menu, in that newVector Assetname that as menu1.
Open that menu 1 and add the items and subitems in this file.
And to select the items implement onOptionsItemSelected() by using the switch [Link] to
know which item is selected implement [Link]().
[Link]
MOBILE APPLICATION DEVELOPMENT LAB MANNUAL Page 39
package [Link].exp1;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
}
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater i=getMenuInflater();
[Link]([Link].menu1,menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
switch ([Link]()) {
case [Link].item1:
[Link](this," The selected Item is 1", Toast.LENGTH_SHORT).show();
return true;
case [Link].item2:
[Link](this," The selected Item is 2", Toast.LENGTH_SHORT).show();
return true;
case [Link].item3:
[Link](this," The selected Item is 3", Toast.LENGTH_SHORT).show();
return true;
case [Link].item4:
[Link](this," The selected Item is 4", Toast.LENGTH_SHORT).show();
return true;
case [Link].item7:
[Link](this," The Item is alaram", Toast.LENGTH_SHORT).show();
return true;
case [Link].sitem1:
[Link](this,” selected sub Item is 1", Toast.LENGTH_SHORT).show();
return true;
case [Link].sitem2:
[Link](this," selected sub item is 2", Toast.LENGTH_SHORT).show();
return true;
default:return [Link](item);
}
}
}
[Link]
MOBILE APPLICATION DEVELOPMENT LAB MANNUAL Page 40
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="[Link]
xmlns:app="[Link]
<item
android:id="@+id/item7"
android:icon="@drawable/ic_alarm_add_black_24dp"
android:title="alaram"
app:showAsAction="ifRoom"
/>
<item
android:id="@+id/item1"
android:icon="@drawable/ic_launcher_background"
android:title="Item 1"
app:showAsAction="never"
/>
<item
android:id="@+id/item2"
android:icon="@color/colorAccent"
android:title="Item 2"
app:showAsAction="never" >
<menu>
<item
android:id="@+id/sitem1"
android:title="sub Item 1"
app:showAsAction="ifRoom"
/>
<item
android:id="@+id/sitem2"
android:title="sub Item 2"
app:showAsAction="ifRoom"
/>
</menu>
</item>
<item
android:id="@+id/item3"
android:title="Item 3"
app:showAsAction="never"
/>
<item
android:id="@+id/item4"
android:title="Item 4"
app:showAsAction="never"
/>
</menu>
Step 4: Run the application the output is displayed.
OUTPUT:
MOBILE APPLICATION DEVELOPMENT LAB MANNUAL Page 41
Exercise Program: b) Design an Action bar which is similar to WHATS APP.
EXPERIMENT – 11
AIM: a) Handling view events
[Link]
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="hello" />
<Button
android:id= “@id/btnsave”
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Save" />
<Button
android:id= “@id/btnopen”
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="open" />
<ImageButton
android:id= “@id/btnsave”
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/icon"/>
MOBILE APPLICATION DEVELOPMENT LAB MANNUAL Page 42
<EditText
android:id= “@id/txtname”
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Checkbox
android:id= “@id/chkautosave”
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="AutoSave" />
<Checkbox
android:id= “@id/star”
style=”?android:att/startStyle”
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RadioGroup
android:id= “@id/rdbgp1”
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RadioButton
android:id= “@id/rdb1”
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=”option1" />
<RadioButton
android:id= “@id/rdb2”
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=”option2" />
</RadioGroup>
<ToggleButton
android:id= “@id/toggle1”
android:layout_width="wrap_content"
android:layout_height="wrap_content” />
</LinearLayout>
[Link]
package net.learn2develop.BasicViews1;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends Activity {
MOBILE APPLICATION DEVELOPMENT LAB MANNUAL Page 43
public void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link]);
Button btnOpen = (Button) findViewById([Link]);
[Link](new [Link]() {
public void onClick(View v) {
DisplayToast(“You have clicked the Open button”);
}
});
Button btnSave = (Button) findViewById([Link]);
[Link](new [Link]()
{
public void onClick(View v) {
DisplayToast(“You have clicked the Save button”);
}
});
CheckBox checkBox = (CheckBox) findViewById([Link]);
[Link](new [Link]()
{
public void onClick(View v) {
if (((CheckBox)v).isChecked())
DisplayToast(“CheckBox is checked”);
else
DisplayToast(“CheckBox is unchecked”);
}
});
RadioGroup radioGroup = (RadioGroup) findViewById([Link].rdbGp1);
[Link](new OnCheckedChangeListener()
{
public void onCheckedChanged(RadioGroup group, int checkedId) {
RadioButton rb1 = (RadioButton) findViewById([Link].rdb1);
if ([Link]()) {
DisplayToast(“Option 1 checked!”);
}
else
{
DisplayToast(“Option 2 checked!”);
}
}
});
ToggleButton toggleButton = (ToggleButton) findViewById([Link].toggle1);
[Link](new [Link]()
{
public void onClick(View v) {
if (((ToggleButton)v).isChecked())
DisplayToast(“Toggle button is On”);
else
DisplayToast(“Toggle button is Off”);
}
});
MOBILE APPLICATION DEVELOPMENT LAB MANNUAL Page 44
}
private void DisplayToast(String msg)
{
[Link](getBaseContext(), msg, Toast.LENGTH_SHORT).show();
}
}
OUTPUT:
Exercise b): Create an application of scoreboard app
[Link]: Create an application by following all the conditions
Registration form by including all basic views,
Display the dialog box as “Please verify all the details once again”
Successfully register, Open the activity is designed with fragments
Navigate to another activity present in different application.
Develop the action bar for that activity.
MOBILE APPLICATION DEVELOPMENT LAB MANNUAL Page 45
MOBILE APPLICATION DEVELOPMENT LAB MANNUAL Page 46