0% found this document useful (0 votes)
2 views49 pages

Nikhil Android

The document is a certificate for Nikhil Santosh Shinde, a student of T.Y.B.Sc.I.T. at Sheth N.K.T.T. College, confirming the completion of practical work in Advanced Mobile Programming for the academic year 2025-26. It includes various programming examples and layouts in Android, demonstrating skills in creating applications with different UI components and lifecycle methods. The document serves as a record of the student's practical work and learning outcomes in the subject.
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)
2 views49 pages

Nikhil Android

The document is a certificate for Nikhil Santosh Shinde, a student of T.Y.B.Sc.I.T. at Sheth N.K.T.T. College, confirming the completion of practical work in Advanced Mobile Programming for the academic year 2025-26. It includes various programming examples and layouts in Android, demonstrating skills in creating applications with different UI components and lifecycle methods. The document serves as a record of the student's practical work and learning outcomes in the subject.
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

Name : Nikhil Santosh Shinde

Course : [Link].I.T.
Div :A
Roll No. : 12
Subject : Advanced Mobile Programming
Year : 2025 - 2026
UNIVERSITY OF MUMBAI
SHETH T.J EDUCATION SOCIETY’S,
SHETH N.K.T.T. COLLEGE OF
COMMERCE & SHETH J.T.T. COLLEGE
OF ARTS, THANE (W)
(AUTONOMOUS)

DEPARTMENT OF INFORMATION TECHNOLOGY

CERTIFICATE

This is to certify that Mr./Miss. Nikhil Santosh Shinde of [Link]. (IT)


Semester VI has completed the practical work in the subject of “Advanced
Mobile Programming” during the academic year 2025-26 under the guidance of
“Mrs. Sneha Gupta” being the partial requirement for the fulfillment of the
Curriculum of Degree of Bachelor of Science in Information Technology,
University of Mumbai.

Place : THANE
Date :

Sign of Subject In charge Sign of External Examiner Sign of External Examiner


INDEX
Advanced Mobile Programming

1. Simple “Hello World” program.

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:text="Hello Nikhil!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</[Link]>

SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)


Advanced Mobile Programming

[Link]
package [Link].practical1_helloworld;

import [Link];

import [Link];

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
}
}

Output :

SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)


Advanced Mobile Programming

2. Programming Android Resources: (Color, Theme, String, Drawable, Dimension, Image)

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"
android:background="@drawable/xyz"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Nikhil"
android:textSize="50dp"
android:textStyle="bold"
android:textColor="@color/Nikhil_Green"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</[Link]>

Main_Activity.java
package [Link].a2_resources;

import [Link];

import [Link];

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
}
}

SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)


Advanced Mobile Programming

[Link]
<resources>
<string name="app_name">2_Resources</string>
<string name="Nikhil">
<item>Hello</item>
<item>Nikhil</item>
</string>
</resources>

[Link]
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
<color name="Nikhil_Blue">#03A9F4</color>
<color name="Nikhil_Green">#00FF55</color>
</resources>

[Link]
<resources xmlns:tools="[Link]
<!-- Base application theme. -->
<style name="[Link].2_Resources"
parent="[Link]">
<!-- Customize your light theme here. -->
<item name="colorPrimary">#8000FF</item>
</style>
<style name="Theme.2_Resources" parent="[Link].2_Resources" />
</resources>

Output:

SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)


Advanced Mobile Programming

3. Programming Activities and fragments:


Activity Life Cycle, Activity methods, Multiple Activities

SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)


Advanced Mobile Programming

Activty_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:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</[Link]>

[Link]
package [Link].a3_emptyviewsactivity;
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
String tag = "Activity Life Cycle ";
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
Log.d(tag,"On Create Method");
}
@Override
protected void onStart() {
[Link]();
Log.d(tag,"On Start Method");
}
@Override
protected void onRestart() {
[Link]();
Log.d(tag,"On Restart Method");
}

@Override
protected void onPause() {
[Link]();
Log.d(tag,"On Pause Method");
Log.i(tag,"Test");

SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)


Advanced Mobile Programming

}
@Override
protected void onResume() {
[Link]();
Log.d(tag,"On Resume Method");
}
@Override
protected void onStop() {
[Link]();
Log.d(tag,"On Stop Method");
}
@Override
protected void onDestroy() {
[Link]();
Log.d(tag,"On Destroy Method");
}
}

Output:

SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)


Advanced Mobile Programming

SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)


Advanced Mobile Programming

SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)


Advanced Mobile Programming

4. Programs related to different layouts


4a)_ Linear_Layout
Activity_main.xml :
<?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:gravity="center"
android:orientation="vertical"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textAlignment="center"
android:textSize="30dp"
android:text="Nikhil Shinde" />
<Button
android:id="@+id/btn1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button 1" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textAlignment="center"
android:padding="10px"
android:textSize="20dp"
android:text="Linear Layout" />
<Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 2" />
</LinearLayout>
</LinearLayout>

SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)


Advanced Mobile Programming

Main_Activity.java :
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
private Button btnClick;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
btnClick = (Button) findViewById([Link].btn1);
[Link](new [Link]() {
public void onClick(View view)
{
[Link](getApplicationContext(), "Button 1 CLicked", Toast.LENGTH_SHORT).show();
}
});
btnClick = (Button) findViewById([Link].btn2);
[Link](new [Link]()
{
public void onClick(View view)
{
[Link](getApplicationContext(), "Button 2 CLicked", Toast.LENGTH_SHORT).show();
}
});
}
}
Output :

SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)


Advanced Mobile Programming

4b)_ RelativeLayout

Activity_main.xml :

<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentStart="true"
android:gravity="center"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textSize="30dp"
android:text="Nikhil Shinde" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textSize="30dp"
android:text="Relative Layout" />

<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 1" />

<Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 2" />

</LinearLayout>

</RelativeLayout>

SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)


Advanced Mobile Programming

Main_Activity.java :
package [Link];

import [Link];

import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {


private Button btnClick;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

btnClick = (Button) findViewById([Link].btn1);


[Link](new [Link]()
{
public void onClick(View view)
{
[Link](getApplicationContext(), "Button 1 Clicked", Toast.LENGTH_SHORT).show();
}
});

btnClick = (Button) findViewById([Link].btn2);


[Link](new [Link]()
{
public void onClick(View view)
{
[Link](getApplicationContext(), "Button 2 Clicked", Toast.LENGTH_SHORT).show();
}
});

}
}
Output :

SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)


Advanced Mobile Programming

4c)_ Table Layout


Activity_main.xml :
<?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:gravity="center"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textAlignment="center"
android:textSize="30dp"
android:text="Table Layout" />

<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1" />

<Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2" />

<Button
android:id="@+id/btn3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3" />
</TableRow>

<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content">

SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)


Advanced Mobile Programming

<Button
android:id="@+id/btn4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4" />

<Button
android:id="@+id/btn5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5" />

<Button
android:id="@+id/btn6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="6" />
</TableRow>

<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<Button
android:id="@+id/btn7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="7" />

<Button
android:id="@+id/btn8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8" />

<Button
android:id="@+id/btn9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="9" />
</TableRow>

</TableLayout>
</LinearLayout>

SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)


Advanced Mobile Programming

Main_Activity.java :
package [Link];

import [Link];

import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {


private Button btnClick;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

btnClick = (Button) findViewById([Link].btn1);


[Link](new [Link]()
{
public void onClick(View view)
{
[Link](getApplicationContext(), "1", Toast.LENGTH_SHORT).show();
}
});

btnClick = (Button) findViewById([Link].btn2);


[Link](new [Link]()
{
public void onClick(View view)
{
[Link](getApplicationContext(), "2", Toast.LENGTH_SHORT).show();
}
});

btnClick = (Button) findViewById([Link].btn3);


[Link](new [Link]()
{
public void onClick(View view)
{
[Link](getApplicationContext(), "3", Toast.LENGTH_SHORT).show();
}
});

btnClick = (Button) findViewById([Link].btn4);


[Link](new [Link]()
{
public void onClick(View view)
{
[Link](getApplicationContext(), "4", Toast.LENGTH_SHORT).show();
SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)
Advanced Mobile Programming

}
});

btnClick = (Button) findViewById([Link].btn5);


[Link](new [Link]()
{
public void onClick(View view)
{
[Link](getApplicationContext(), "5", Toast.LENGTH_SHORT).show();
}
});

btnClick = (Button) findViewById([Link].btn6);


[Link](new [Link]()
{
public void onClick(View view)
{
[Link](getApplicationContext(), "6", Toast.LENGTH_SHORT).show();
}
});

btnClick = (Button) findViewById([Link].btn7);


[Link](new [Link]()
{
public void onClick(View view)
{
[Link](getApplicationContext(), "7", Toast.LENGTH_SHORT).show();
}
});

btnClick = (Button) findViewById([Link].btn8);


[Link](new [Link]()
{
public void onClick(View view)
{
[Link](getApplicationContext(), "8", Toast.LENGTH_SHORT).show();
}
});

btnClick = (Button) findViewById([Link].btn9);


[Link](new [Link]()
{
public void onClick(View view)
{
[Link](getApplicationContext(), "9", Toast.LENGTH_SHORT).show();
}
});
}
}

SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)


Advanced Mobile Programming

Output :

SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)


Advanced Mobile Programming

4d)_ FrameLayout
Activity_main.xml :
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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="50sp"
android:textAlignment="center"
android:text="Frame Layout" />
<ImageView
android:layout_height="match_parent"
android:layout_width="match_parent"
android:src="@drawable/x" > </ImageView>
</FrameLayout>

Main_Activity.java :
package [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
}
}
Output :

SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)


Advanced Mobile Programming

4e)_ Grid Layout


Activity_main.xml :
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnCount="3"
android:rowCount="3"
android:orientation="horizontal">

<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1" />

<Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2" />

<Button
android:id="@+id/btn3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3" />

<Button
android:id="@+id/btn4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4" />

<Button
android:id="@+id/btn5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5" />

<Button
android:id="@+id/btn6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="6" />

<Button
android:id="@+id/btn7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="7" />
SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)
Advanced Mobile Programming

<Button
android:id="@+id/btn8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8" />

<Button
android:id="@+id/btn9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="9" />
</GridLayout>

Main_Activity.java :
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {


private Button btnClick;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

btnClick = findViewById([Link].btn1);
[Link](new [Link]() {
@Override
public void onClick(View view) {
showToast("Button 1 clicked");
}
});

btnClick = findViewById([Link].btn2);
[Link](new [Link]() {
@Override
public void onClick(View view) {
showToast("Button 2 clicked");
}
});

btnClick = findViewById([Link].btn3);
[Link](new [Link]() {
@Override
public void onClick(View view) {
showToast("Button 3 clicked");
}
SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)
Advanced Mobile Programming

});

btnClick = findViewById([Link].btn4);
[Link](new [Link]() {
@Override
public void onClick(View view) {
showToast("Button 4 clicked");
}
});

btnClick = findViewById([Link].btn5);
[Link](new [Link]() {
@Override
public void onClick(View view) {
showToast("Button 5 clicked");
}
});

btnClick = findViewById([Link].btn6);
[Link](new [Link]() {
@Override
public void onClick(View view) {
showToast("Button 6 clicked");
}
});

btnClick = findViewById([Link].btn7);
[Link](new [Link]() {
@Override
public void onClick(View view) {
showToast("Button 7 clicked");
}
});

btnClick = findViewById([Link].btn8);
[Link](new [Link]() {
@Override
public void onClick(View view) {
showToast("Button 8 clicked");
}
});

btnClick = findViewById([Link].btn9);
[Link](new [Link]() {
@Override
public void onClick(View view) {
showToast("Button 9 clicked");
}
});
}

SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)


Advanced Mobile Programming

private void showToast(String message) {


[Link](getApplicationContext(), message, Toast.LENGTH_SHORT).show();
}
}

Output :

SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)


Advanced Mobile Programming

PRACTICAL 5

Programming UI elements AppBar, Fragments, UI Components

5a. Demonstration of Application Bar

ProjectName -> App -> Src -> Main -> Res -> values-> [Link] The default line is: <style
name="Theme.Practical5" parent="[Link]"> Change to:

<style name="Theme.Practical5" parent="[Link]">

SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)


Advanced Mobile Programming

[Link]
<resources xmlns:tools="[Link]
<!-- Base application theme. -->
<style name="[Link]"
parent="[Link]">
<!-- Customize your light theme here. -->
<!-- <item name="colorPrimary">@color/my_light_primary</item> -->
</style>

<style name="[Link]" parent="[Link]" />


</resources>

Activity_main.xml

<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<include android:id="@+id/t" layout="@layout/toolbar" />

</RelativeLayout>

[Link]

<?xml version="1.0" encoding="utf-8"?>


<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FF9900"
>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="cursive"
android:text="Practical 5"
android:textSize="29dp"
android:textStyle="bold" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="120dp"
android:text="LogOut" />
</[Link]>

SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)


Advanced Mobile Programming

Main_Activity.java
package [Link];

import [Link];

import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

Toolbar tbar = findViewById([Link].t);


setSupportActionBar(tbar);
}
}

Output:

SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)


Advanced Mobile Programming

5b. Demonstration of UI Components

Activity_main.xml

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"

tools:context=".MainActivity">

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textAlignment="center"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Practical 5 : UI Components"
android:textSize="30dp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Calculator"
android:layout_gravity="center"
android:textSize="30dp" />

<EditText
android:id="@+id/et1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:hint="Number 1"
android:inputType="number" />

<EditText
android:id="@+id/et2"
android:layout_width="match_parent"
android:layout_height="50dp"
android:hint="Number 2"
android:inputType="number"
/>

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

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

SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)


Advanced Mobile Programming

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

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

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

<TextView
android:id="@+id/tv1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Output :"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
/>
</LinearLayout>
</LinearLayout>

SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)


Advanced Mobile Programming

[Link]
package [Link].a5_uicomponents;

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

import [Link];

public class MainActivity extends AppCompatActivity {


EditText t1, t2;
Button b1, b2, b3, b4, b5;
TextView res;
int n1 = 0, n2 = 0;
String s1, s2;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

t1 = (EditText) findViewById([Link].et1);
t2 = (EditText) findViewById([Link].et2);

b1 = (Button) findViewById([Link]);
b2 = (Button) findViewById([Link]);
b3 = (Button) findViewById([Link]);
b4 = (Button) findViewById([Link]);
b5 = (Button) findViewById([Link]);

res = (TextView) findViewById([Link].tv1);

[Link](new [Link]() {
@Override
public void onClick(View v) {
try {
String s1 = [Link]().toString();
String s2 = [Link]().toString();
n1 = [Link](s1);
n2 = [Link](s2);
int sum = n1 + n2;
[Link]("Addition=" + sum);
} catch (NumberFormatException e) {
}
}
});

[Link](new [Link]() {
@Override
public void onClick(View v) {
try {
String s1 = [Link]().toString();
String s2 = [Link]().toString();
n1 = [Link](s1);
n2 = [Link](s2);
int sum = n1 - n2;
[Link]("Subtraction =" + sum);
} catch (NumberFormatException e) {

SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)


Advanced Mobile Programming

}
}
});

[Link](new [Link]() {
@Override
public void onClick(View v) {
try {
String s1 = [Link]().toString();
String s2 = [Link]().toString();
n1 = [Link](s1);
n2 = [Link](s2);
int sum = n1 * n2;
[Link]("Multiplication=" + sum);
} catch (NumberFormatException e) {
}
}
});

[Link](new [Link]() {
@Override
public void onClick(View v) {
try {
String s1 = [Link]().toString();
String s2 = [Link]().toString();
n1 = [Link](s1);
n2 = [Link](s2);
int sum = n1 / n2;
[Link]("Division=" + sum);
} catch (NumberFormatException e) {
}
}
});

[Link](new [Link]() {
@Override
public void onClick(View v) {
[Link]("Output");
}
});
}
}

SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)


Advanced Mobile Programming

Output :

SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)


Advanced Mobile Programming

5c. Fragments

Activty_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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button1"
android:text="News"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button2"
android:text="Sports"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button3"
android:text="Entertainment"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<[Link]
android:id="@+id/fragmentContainerView"
android:name="[Link].a5b_fragments.News"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" >
</[Link]>
</LinearLayout>
</LinearLayout>

SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)


Advanced Mobile Programming

Fragment_ent.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".EntFragment">

<!-- TODO: Update blank fragment layout -->


<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="50sp"
android:textAlignment="center"
android:text="Entertainment" />

</FrameLayout>

Fragment_news.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".News">

<!-- TODO: Update blank fragment layout -->


<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="50sp"
android:textAlignment="center"
android:text="News" />

</FrameLayout>

Fragment_sports.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SportsFragment">

<!-- TODO: Update blank fragment layout -->


<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="50sp"
android:textAlignment="center"
android:text="Sports" />

</FrameLayout>

SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)


Advanced Mobile Programming

[Link]
package [Link].a5b_fragments;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

Button btnnews=findViewById([Link].button1);
[Link](new [Link]() {
@Override
public void onClick(View view) {
FragmentManager fragmentManager = getSupportFragmentManager();
[Link]()
.replace([Link], [Link], null)
.setReorderingAllowed(true)
.addToBackStack("name") // Name can be null
.commit();
}
});
Button btnsports=findViewById([Link].button2);
[Link](new [Link]() {
@Override
public void onClick(View view) {
FragmentManager fragmentManager = getSupportFragmentManager();
[Link]()
.replace([Link], [Link], null)
.setReorderingAllowed(true)
.addToBackStack("name") // Name can be null
.commit();

}
});
Button btnent=findViewById([Link].button3);
[Link](new [Link]() {
@Override
public void onClick(View view) {
FragmentManager fragmentManager = getSupportFragmentManager();
[Link]()
.replace([Link], [Link], null)
.setReorderingAllowed(true)
.addToBackStack("name") // Name can be null
.commit();
}
});

}
}

SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)


Advanced Mobile Programming

Output:

SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)


Advanced Mobile Programming

6. Menus
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:text="Menu Bar Demonstration"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</[Link]>

Main_Activity.java :
package [Link].a6_menus;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate([Link],menu);
return true;
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
switch ([Link]()){
case [Link]:
[Link](this,"You have clicked on settings",Toast.LENGTH_SHORT).show();
return true;
case [Link]:
[Link](this,"You have clicked on About Us",Toast.LENGTH_SHORT).show();
return true;
case [Link]:
[Link](this,"You have clicked on Share",Toast.LENGTH_SHORT).show();
return true;
case [Link]:
[Link](this,"You have clicked on Log Out",Toast.LENGTH_SHORT).show();
return true;
default:
return [Link](item);
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
}
}

SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)


Advanced Mobile Programming

Output :

SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)


Advanced Mobile Programming

7) Alert Dialog
Activity_main.xml :

<?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:gravity="center"
tools:context=".MainActivity">
<Button
android:id="@+id/button"
android:layout_width="141dp"
android:layout_height="79dp"
android:text="Click ME" />
</LinearLayout>

Main_Activity.java :
package [Link].a7_alertdialog;

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {


Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
btn= findViewById([Link]);
[Link](new [Link]() {
@Override
public void onClick(View view) {
openAlertBox();
}
}
);
}
private void openAlertBox() {
[Link] builder = new
[Link]([Link]);
[Link]("Do you want to exit ?");
[Link]([Link].baseline_crisis_alert_24);
[Link]("Alert !");

[Link](false);

[Link]("Yes", ([Link])
(dialog, which) -> {
// When the user click yes button then app will close
finish();
});

[Link]("No", ([Link])
(dialog, which) -> {
// If user click no then dialog box is canceled.
[Link]();
});

SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)


Advanced Mobile Programming

// Create the Alert dialog


AlertDialog alertDialog = [Link]();
// Show the Alert Dialog box
[Link]();
}
}

Output :

SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)


Advanced Mobile Programming

Practical 8

Database Programming with SQLite


Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Name :"
android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText_name"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:text="Surname :"
android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText_surname"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:text="Marks :"
android:textAppearance="?android:attr/textAppearanceLarge" />

<EditText
android:id="@+id/editText_name"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignTop="@+id/textView"
android:layout_toEndOf="@+id/textView"
android:layout_toRightOf="@+id/textView"
android:hint="Enter Your Name" />

<EditText
android:id="@+id/editText_surname"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignTop="@+id/textView2"
android:layout_toEndOf="@+id/textView2"
android:layout_toRightOf="@+id/textView2"
android:hint="Enter Your Surname" />

<EditText
android:id="@+id/editText_Marks"
android:layout_width="match_parent"
android:layout_height="50dp"

SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)


Advanced Mobile Programming

android:layout_below="@+id/editText_surname"
android:layout_toEndOf="@+id/textView3"
android:layout_toRightOf="@+id/textView3"
android:hint="Enter The Marks" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Data"
android:id="@+id/button_add"
android:layout_below="@+id/editText_Marks"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="76dp" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="View All"
android:id="@+id/button_viewAll"
android:layout_above="@+id/button_update"
android:layout_centerHorizontal="true" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Update"
android:id="@+id/button_update"
android:layout_below="@+id/button_add"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

<TextView
android:id="@+id/textView_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:layout_below="@+id/editText_Marks"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:text="id :"
android:textAppearance="?android:attr/textAppearanceLarge" />

<EditText
android:id="@+id/editText_id"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignTop="@+id/textView_id"
android:layout_toEndOf="@+id/textView3"
android:layout_toRightOf="@+id/textView3"
android:hint="Enter ID to Update Or Delete !" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Delete"
android:id="@+id/button_delete"
android:layout_centerVertical="true"
android:layout_below="@+id/button_viewAll"
android:layout_alignLeft="@+id/button_viewAll"
android:layout_alignStart="@+id/button_viewAll" />

</RelativeLayout>

SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)


Advanced Mobile Programming

[Link]

package [Link].a8_database;

import [Link];
import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {

DatabaseHelper myDb;
EditText editName,editSurname,editMarks ,editTextId;
Button btnAddData;
Button btnviewAll;
Button btnDelete;
Button btnviewUpdate;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
myDb = new DatabaseHelper(this);
editName = (EditText)findViewById([Link].editText_name);
editSurname = (EditText)findViewById([Link].editText_surname);
editMarks = (EditText)findViewById([Link].editText_Marks);
editTextId = (EditText)findViewById([Link].editText_id);
btnAddData = (Button)findViewById([Link].button_add);
btnviewAll = (Button)findViewById([Link].button_viewAll);
btnviewUpdate= (Button)findViewById([Link].button_update);
btnDelete= (Button)findViewById([Link].button_delete);
AddData();
viewAll();
UpdateData();
DeleteData();
}
public void DeleteData() {
[Link](
new [Link]() {
@Override
public void onClick(View v) {
Integer deletedRows = [Link]([Link]().toString());
if(deletedRows > 0)
[Link]([Link],"Data Deleted",Toast.LENGTH_LONG).show();
else
[Link]([Link],"ID Not Found",Toast.LENGTH_LONG).show();
}
}
);
}
public void UpdateData() {
[Link](
new [Link]() {
@Override
public void onClick(View v) {
boolean isUpdate = [Link]([Link]().toString(),
[Link]().toString(),
[Link]().toString(),[Link]().toString());
if(isUpdate == true)
[Link]([Link],"Data Updated",Toast.LENGTH_LONG).show();

SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)


Advanced Mobile Programming

else
[Link]([Link],"Data not Updated",Toast.LENGTH_LONG).show();
}
}
);
}
public void AddData() {
[Link](
new [Link]() {
@Override
public void onClick(View v) {
boolean isInserted = [Link]([Link]().toString(),
[Link]().toString(),
[Link]().toString() );
if(isInserted == true)
[Link]([Link],"Data Inserted",Toast.LENGTH_LONG).show();
else
[Link]([Link],"Data not Inserted",Toast.LENGTH_LONG).show();
}
}
);
}
public void viewAll() {
[Link](
new [Link]() {
@Override
public void onClick(View v) {
Cursor res = [Link]();
if([Link]() == 0) {
// show message
showMessage("Error","Nothing found");
return;
}
StringBuffer buffer = new StringBuffer();
while ([Link]()) {
[Link]("Id :"+ [Link](0)+"\n");
[Link]("Name :"+ [Link](1)+"\n");
[Link]("Surname :"+ [Link](2)+"\n");
[Link]("Marks :"+ [Link](3)+"\n\n");
}
// Show all data
showMessage("Data",[Link]());
}
}
);
}
public void showMessage(String title,String Message){
[Link] builder = new [Link](this);
[Link](true);
[Link](title);
[Link](Message);
[Link]();
}

SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)


Advanced Mobile Programming

[Link]

package [Link].a8_database;

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class DatabaseHelper extends SQLiteOpenHelper {


public static final String DATABASE_NAME = "[Link]";
public static final String TABLE_NAME = "student_table";
public static final String COL_1 = "ID";
public static final String COL_2 = "NAME";
public static final String COL_3 = "SURNAME";
public static final String COL_4 = "MARKS";

public DatabaseHelper(Context context) {


super(context, DATABASE_NAME, null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
[Link]("create table " + TABLE_NAME +" (ID INTEGER PRIMARY KEY AUTOINCREMENT,NAME TEXT,SURNAME TEXT,MARKS
INTEGER)");
}

@Override
public void onUpgrade(SQLiteDatabase db, int i, int i1) {
[Link]("DROP TABLE IF EXISTS "+TABLE_NAME);
onCreate(db);
}
public boolean insertData(String name,String surname,String marks) {
SQLiteDatabase db = [Link]();
ContentValues contentValues = new ContentValues();
[Link](COL_2,name);
[Link](COL_3,surname);
[Link](COL_4,marks);
long result = [Link](TABLE_NAME,null ,contentValues);
if(result == -1)
return false;
else
return true;
}
public Cursor getAllData() {
SQLiteDatabase db = [Link]();
Cursor res = [Link]("select * from "+TABLE_NAME,null);
return res;
}
public boolean updateData(String id,String name,String surname,String marks) {
SQLiteDatabase db = [Link]();
ContentValues contentValues = new ContentValues();
[Link](COL_1,id);
[Link](COL_2,name);
[Link](COL_3,surname);
[Link](COL_4,marks);
[Link](TABLE_NAME, contentValues, "ID = ?",new String[] { id });
return true;
}
public Integer deleteData (String id) {
SQLiteDatabase db = [Link]();
return [Link](TABLE_NAME, "ID = ?",new String[] {id});
}
}

SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)


Advanced Mobile Programming

Output :

Insert Data View All

SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)


Advanced Mobile Programming

Update Data :

Delete Data :

SHETH N.K.T.T. COLLEGE, THANE [Link] (2023-24)

You might also like