0% found this document useful (0 votes)
7 views71 pages

Android Program-Solution

The document outlines the steps for setting up an Android development environment and explains various components of Android applications, such as Activities, Fragments, Services, and Broadcast Receivers. It includes practical exercises for developing a 'Hello World' application, understanding the activity lifecycle, and designing user interfaces using different layouts and widgets. Additionally, it covers event handling for buttons, checkboxes, and radio buttons in Android applications.

Uploaded by

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

Android Program-Solution

The document outlines the steps for setting up an Android development environment and explains various components of Android applications, such as Activities, Fragments, Services, and Broadcast Receivers. It includes practical exercises for developing a 'Hello World' application, understanding the activity lifecycle, and designing user interfaces using different layouts and widgets. Additionally, it covers event handling for buttons, checkboxes, and radio buttons in Android applications.

Uploaded by

Pampati Nagaraju
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Mobile Application Development

Practical No– 01
Set-up of Android development environment, managing AVD and understanding its
various components.

Android development environment:

Step 1: Install Android Studio


Download Android Studio from the website: [Link]
Run the downloaded installer and follow the installation wizard instructions.
During the installation, select the components that we want to install, such as the Android SDK,
emulator, and development tools.
Step 2: Launch Android Studio
After the installation is complete, launch Android Studio.
Step 3: Configure SDK and AVD Manager
On the Android Studio Welcome screen, click on "Configure" in the bottom-right corner and
select "SDK Manager."
The SDK Manager allows us to install SDK components, platform versions, and system images
for different device configurations.
Step 4: Install SDK Platforms and System Images
In the SDK Platforms tab, install the Android versions (API levels) that we want to target in our
app. For example, Android 11 (API 30).
Step 5: Create an AVD (Android Virtual Device)
After installing the necessary SDK components, click on "AVD Manager".
In the AVD Manager, click "Create Virtual Device."
Choose the device type we want to emulate (e.g., Pixel 4) and click "Next."
Select a system image for the virtual device and click "Next."
Configure the AVD properties (e.g., device orientation, scale, RAM, and storage) and click
"Finish" to create the AVD.
Step 6: Run the AVD
Back in the AVD Manager, click the green "Play" button next to the AVD we created to start
the virtual device.
The AVD will start up, and the Android system running on the virtual device.
Step 7: Use AVD for Testing
In Android Studio, open Android project. On the toolbar, select AVD from the device drop-
down menu. Click the "Run" button to run app on the selected AVD.
Practical No– 02
Understanding of Various Components available in Android Application.

Android applications are built using various components that interact with each other to provide
the desired functionality and user experience.

Activities: An activity represents a single screen with a user interface. It is the most
fundamental component of an Android app and is responsible for interacting with the user. An
application may consist of one or multiple activities. Each activity extends the Activity class
and typically corresponds to a specific user interaction.

Fragments: Fragments are modular sections of an activity that can be combined and reused
across multiple activities. They are useful for creating responsive user interfaces, especially on
devices with varying screen sizes. Fragments extend the Fragment class and are managed by
activities.

Services: A service is a component that runs in the background, independent of any user
interface. It performs long-running operations or handles tasks that should continue to execute
even when app is not in the foreground. Services can be used to play music, download data, or
handle network transactions.

Broadcast Receivers: A broadcast receiver is a component that listens for and responds to
system-wide broadcasts. These broadcasts can be sent by the Android system or other apps.
Broadcast receivers allow your app to respond to events, such as incoming SMS messages,
network connectivity changes, or battery status updates.

Content Providers: A content provider allows the app to share data with other apps securely. It
acts as an interface to access and manage the app's data, which can be stored in a database, file,
or any other data source. Content providers enable inter-app data sharing, allowing other apps to
read or modify the data based on defined permissions.

Intents: Intents are messaging objects used to communicate between components within an app
or between different apps. They facilitate starting activities, services, or broadcasting events.
Intents can carry data along with them to pass information between components.

Layouts: Android uses XML-based layout files to define the user interface of an activity or
fragment. These layout files specify how different UI elements are arranged and displayed on
the screen.

Page 2
Resources: Android apps use resources such as strings, colors, styles, and images. These
resources are kept separately from the code, allowing for easy localization and management.

Manifest File: The [Link] file contains important information about the app,
such as the app's package name, components, permissions required, and hardware features used.
It acts as a configuration file for the app.

Gradle Build System: Gradle is used to manage the build process of an Android app. It defines
dependencies, compiles code, and packages the app for distribution.

Page 3
Mobile Application Development

Develop a “Hello World” Application in Android and understand the structure of an


Android Application.

activity_main.xml

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


<LinearLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World"
android:textSize="24sp" />
</LinearLayout>

[Type here]
Mobile Application Development

[Type here]
Mobile Application Development

Practical No– 04

AIM:- Develop Android Application to demonstrate methods of Activity Life Cycle.

[Link]

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

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
[Link]([Link],"onCreate method
called",Toast.LENGTH_LONG).show();
}
@Override
protected void onStart()
{
[Link]();
[Link]([Link],"onStart method
called",Toast.LENGTH_LONG).show();
}
@Override
protected void onResume()
{
[Link]();
[Link]([Link],"onResume method
called",Toast.LENGTH_LONG).show();
}

@Override
protected void onRestart()
{
[Link]();
Mobile Application Development

[Link]([Link],"onRestart method
called",Toast.LENGTH_LONG).show();
}
@Override
protected void onStop()
{
[Link]();
[Link]([Link],"onStop method
called",Toast.LENGTH_LONG).show();
}
@Override
protected void onPause()
{
[Link]();
[Link]([Link],"onPause method
called",Toast.LENGTH_LONG).show();
}
@Override
protected void onDestroy()
{
[Link]();
[Link]([Link],"onDestroy method
called",Toast.LENGTH_LONG).show();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate([Link], menu);
return true;
}
}
Mobile Application Development

Practical No– 05

AIM:- Design Android Activities using LinearLayout, RelativeLayout, GridView,


FrameLayout, and ConstraintLayout.

LinearLayout:

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is a LinearLayout"
android:textSize="20sp" />
<!-- Add more views as needed -->
</LinearLayout>

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">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is a RelativeLayout"
android:textSize="20sp" />
</RelativeLayout>

GridView:
Mobile Application Development

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<GridView
xmlns:android="[Link]
android:id="@+id/gridView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="3"
android:verticalSpacing="8dp"
android:horizontalSpacing="8dp"
android:padding="8dp"
android:gravity="center" />

FrameLayout:

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher_foreground"
android:contentDescription="Image in FrameLayout" />
</FrameLayout>

ConstraintLayout:

activity_main.xml

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


<[Link]
xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent">
Mobile Application Development

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is a ConstraintLayout"
android:textSize="20sp"
android:layout_marginTop="16dp"
android:layout_marginStart="16dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent" />

</[Link]>
Mobile Application Development

Practical No– 06

AIM:- Design various Activities using different Layouts and available Widgets
(TextView, EditText, Button, RadioButton, CheckBox, ImageButton, ToggleButton,
TimePicker, DatePicker, ProgressBar, ImageView) to make the user-friendly GUI.

1. MainActivity (Linear Layout with EditText and Button):

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


<LinearLayout
xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<EditText
android:id="@+id/etName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter your name" />

<Button
android:id="@+id/btnSubmit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit" />

</LinearLayout>

2. SecondActivity (Relative Layout with CheckBox, RadioButton, and ToggleButton):

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


<RelativeLayout
xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent">

<CheckBox
android:id="@+id/chkSound"
Mobile Application Development

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enable Sound" />

<RadioButton
android:id="@+id/radioOption1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/chkSound"
android:text="Option 1" />

<RadioButton
android:id="@+id/radioOption2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/radioOption1"
android:text="Option 2" />

<ToggleButton
android:id="@+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/radioOption2"
android:textOff="Off"
android:textOn="On" />

</RelativeLayout>

3. ThirdActivity (Constraint Layout with TimePicker and DatePicker):

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


<[Link]
xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">

<TimePicker
android:id="@+id/timePicker"
android:layout_width="wrap_content"
Mobile Application Development

android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="20dp" />

<DatePicker
android:id="@+id/datePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/timePicker"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="20dp" />

</[Link]>

4. FourthActivity (Frame Layout with ProgressBar and ImageView):

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


<FrameLayout
xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">

<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true" />

<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher_foreground"
android:contentDescription="Sample Image1"
android:visibility="gone" />
</FrameLayout>
Mobile Application Development

Practical No– 07

AIM:- Develop code to demonstrate different ways of Handling different events


(onClick, onLongClick etc.) over Button, EditText etc. to perform action in Android
application at run-time.

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

public class MainActivity extends Activity {


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

et1=(EditText)findViewById([Link].editText1);
b1=(Button)findViewById([Link].button1);

[Link](new [Link]() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
String s=[Link]().toString();
Toast t=[Link](getApplicationContext(), s,
Toast.LENGTH_LONG);
[Link]();
}
});

}
Mobile Application Development

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate([Link], menu);
return true;
}

}
Mobile Application Development

Practical No– 08

AIM:- Develop code to demonstrate Event handling of CheckBox and RadioButton


selection.

Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">

<CheckBox
android:id="@+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Check Me" />

<RadioButton
android:id="@+id/radioOption1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 1" />

<RadioButton
android:id="@+id/radioOption2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 2" />

</LinearLayout>
Mobile Application Development

[Link]

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

public class MainActivity extends AppCompatActivity {

private CheckBox checkBox;


private RadioButton radioOption1, radioOption2;

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

checkBox = findViewById([Link]);
radioOption1 = findViewById([Link].radioOption1);
radioOption2 = findViewById([Link].radioOption2);

[Link](new
[Link]() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{ if (isChecked) {
showToast("CheckBox is checked!");
} else {
showToast("CheckBox is unchecked!");
}
}
});

RadioGroup radioGroup = findViewById([Link]);


[Link](new [Link]()
{
Mobile Application Development

@Override
public void onCheckedChanged(RadioGroup group, int checkedId)
{ switch (checkedId) {
case [Link].radioOption1:
showToast("Option 1 is selected!");
break;
case [Link].radioOption2:
showToast("Option 2 is selected!");
break;
}
}
});
}

private void showToast(String message) {


[Link](this, message, Toast.LENGTH_SHORT).show();
}
}
Mobile Application Development

Practical No– 09

AIM:- Develop code to navigate between different activities and pass the data from one
activity to other activity using Intent.

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

public class MainActivity extends Activity {


Button b1;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
b1=(Button)findViewById([Link].button1);
[Link](new [Link]() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i= new Intent(getApplicationContext(),[Link]);
startActivity(i);
}
});
}
}
Mobile Application Development

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

public class Second extends Activity {

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

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate([Link], menu);
return true;
}

}
Mobile Application Development

Practical No– 10
AIM:- Develop an android application to store data locally using Shared Preferences
and access-modify in different activities.

Create two activities:


MainActivity (Default activity)
SettingsActivity

Implement the layouts for both activities.


activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">

<Button
android:id="@+id/btnSettings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Open Settings" />

</LinearLayout>

activity_settings.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
android:orientation="vertical">

<EditText
android:id="@+id/etName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Mobile Application Development

android:hint="Enter your name" />

<EditText
android:id="@+id/etEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter your email" />

<Button
android:id="@+id/btnSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save" />

</LinearLayout>

Implement the logic for storing and accessing data using Shared Preferences in the
MainActivity and SettingsActivity:

[Link]:

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

public class MainActivity extends AppCompatActivity {

private static final String PREF_NAME = "MyPrefs";


private Button btnSettings;

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

btnSettings = findViewById([Link]);
Mobile Application Development

[Link](new [Link]() {
@Override
public void onClick(View v) {
startActivity(new Intent([Link], [Link]));
}
});
}
}

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

public class SettingsActivity extends AppCompatActivity {

private static final String PREF_NAME = "MyPrefs";


private EditText etName, etEmail;
private Button btnSave;

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

etName = findViewById([Link]);
etEmail = findViewById([Link]);
btnSave = findViewById([Link]);

// Load the saved data from Shared Preferences


SharedPreferences preferences = getSharedPreferences(PREF_NAME,
MODE_PRIVATE);
String savedName = [Link]("name", "");
String savedEmail = [Link]("email", "");
Mobile Application Development

[Link](savedName);
[Link](savedEmail);

[Link](new [Link]() {
@Override
public void onClick(View v) {
// Save the data to Shared Preferences
[Link] editor = getSharedPreferences(PREF_NAME,
MODE_PRIVATE).edit();
[Link]("name", [Link]().toString());
[Link]("email",
[Link]().toString()); [Link]();
finish(); // Close the activity after saving
}
});
}
}

Add both activities to the [Link] file:

xml
Copy code
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="[Link]" />
<category android:name="[Link]" />
</intent-filter>
</activity>
<activity android:name=".SettingsActivity" />
Mobile Application Development

Practical No– 11
Develop the code to implement the ListView and the Spinner views, perform add, update,
remove items operations and implement the item selection event handling over ListView
and Spinner for appropriate example.

Program -1
To implement a ListView with add, update, and remove item operations along with item
selection event handling in Android.

activity_main.xml
<RelativeLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent">

<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Item"
android:onClick="addItem" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Update Item"
android:onClick="updateItem" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Remove Item"
android:onClick="removeItem" />

</RelativeLayout>
Mobile Application Development

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

import [Link];

import [Link];

public class MainActivity extends AppCompatActivity {

private ListView listView;


private ArrayList<String> items;
private ArrayAdapter<String> adapter;

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

listView = findViewById([Link]);
items = new ArrayList<>();
adapter = new ArrayAdapter<>(this, [Link].simple_list_item_1, items);

// Set the adapter to the ListView


[Link](adapter);

// Add sample data to the list


[Link]("Item 1");
[Link]("Item 2");
[Link]("Item 3");
[Link]();

// Handle item selection


[Link](new [Link]() {
@Override
Mobile Application Development

public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{ String selectedItem = [Link](position);
[Link]([Link], "Selected item: " + selectedItem,
Toast.LENGTH_SHORT).show();
}
});
}

// Add new item to the list


public void addItem(View view)
{ [Link]("New Item");
[Link]();
}

// Update the selected item in the list


public void updateItem(View view) {
int selectedPosition = [Link]();
if (selectedPosition != ListView.INVALID_POSITION) {
String updatedItem = "Updated Item";
[Link](selectedPosition, updatedItem);
[Link]();
} else {
[Link](this, "Select an item to update", Toast.LENGTH_SHORT).show();
}
}

// Remove the selected item from the list


public void removeItem(View view) {
int selectedPosition = [Link]();
if (selectedPosition != ListView.INVALID_POSITION) {
[Link](selectedPosition);
[Link]();
} else {
[Link](this, "Select an item to remove", Toast.LENGTH_SHORT).show();
}
}
}
Mobile Application Development

Program -2
To implement a SpinnerView with add, update, and remove item operations along with item
selection event handling in Android

 In the layout XML file (activity_spinner.xml), add a Spinner, EditText, and three Buttons
(Add, Update, and Remove) to allow user interaction.

Java Code

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

import [Link];

import [Link];

public class SpinnerActivity extends AppCompatActivity


{ private Spinner spinner;
private ArrayAdapter<String> spinnerAdapter;
private ArrayList<String> items;
private EditText editText;
private Button addButton;
private Button updateButton;
private Button removeButton;

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

// Initialize views
spinner = findViewById([Link]);
editText = findViewById([Link].edit_text);
Mobile Application Development

addButton = findViewById([Link].add_button);
updateButton = findViewById([Link].update_button);
removeButton = findViewById([Link].remove_button);

// Initialize data
items = new ArrayList<>();
[Link]("Item 1");
[Link]("Item 2");
[Link]("Item 3");

// Initialize spinner adapter


spinnerAdapter = new ArrayAdapter<>(this, [Link].simple_spinner_item,
items);

[Link]([Link].simple_spinner_dropdown_item)
;
[Link](spinnerAdapter);

// Handle item selection event


[Link](new [Link]()
{ @Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
{ String selectedItem = [Link](position).toString();
[Link]([Link], "Selected: " + selectedItem,
Toast.LENGTH_SHORT).show();
}

@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});

// Handle add button click


[Link](new [Link]() {
@Override
public void onClick(View v) {
String newItem = [Link]().toString().trim();
if (![Link]()) {
[Link](newItem);
[Link]();
Mobile Application Development

[Link]().clear();
}
}
});

// Handle update button click


[Link](new [Link]() {
@Override
public void onClick(View v) {
int selectedItemPosition = [Link]();
String updatedItem = [Link]().toString().trim();
if (selectedItemPosition != AdapterView.INVALID_POSITION &&
![Link]()) {
[Link](selectedItemPosition, updatedItem);
[Link]();
[Link]().clear();
}
}
});

// Handle remove button click


[Link](new [Link]() {
@Override
public void onClick(View v) {
int selectedItemPosition = [Link]();
if (selectedItemPosition != AdapterView.INVALID_POSITION) {
[Link](selectedItemPosition);
[Link]();
[Link]().clear();
}
}
});
}
}
Mobile Application Development

Practical No– 12
Develop the code to manage Permission using Manifest file and run time from Activity,
and toggle state of WiFi and Bluetooth.

Program – 1

To manage permissions in Android, you need to declare permissions in the


[Link] file and request them at runtime in the Activity when needed.

 Add Permissions to [Link]: Open your [Link] file and


add the necessary permissions. For this example, let's add the
"READ_EXTERNAL_STORAGE" permission to read external storage.

[Link] code

<manifest xmlns:android="[Link]
package="[Link]">

<uses-permission android:name="[Link].READ_EXTERNAL_STORAGE" />

<application
<!-- Your application details here -->
</application>

</manifest>

Java code

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

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

public class YourActivity extends AppCompatActivity {


Mobile Application Development

private static final int REQUEST_READ_EXTERNAL_STORAGE = 1;

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

// Check if the required permission is granted or not


if ([Link](this,
[Link].READ_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED) {
// Permission is already granted
// You can perform the tasks that require this permission here
// For example, access the external storage
} else {
// Permission is not granted
// Request the permission from the user
[Link](this,
new String[]{[Link].READ_EXTERNAL_STORAGE},
REQUEST_READ_EXTERNAL_STORAGE);
}
}

// Handle the permission request result


@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
@NonNull int[] grantResults) {
if (requestCode == REQUEST_READ_EXTERNAL_STORAGE)
{ if ([Link] > 0 && grantResults[0] ==
PackageManager.PERMISSION_GRANTED) {
// Permission is granted
// Perform the tasks that require this permission here
// For example, access the external storage
} else {
// Permission is denied
// You can handle this situation here, e.g., show an explanation or disable
functionality
[Link](this, "Permission Denied", Toast.LENGTH_SHORT).show();
}
}
Mobile Application Development

}
}

 In this code, we first check if the permission is already granted using


[Link]().
 If it's not granted, we request the permission using
[Link]().
 The user will see a dialog asking for permission, and the result will be handled in
onRequestPermissionsResult().

Program – 2

Implement toggle state of WiFi and Bluetooth in android.

 To implement the toggle state of WiFi and Bluetooth in an Android application, you
can use the WifiManager and BluetoothAdapter classes provided by the Android
framework.
 Add necessary permissions to the [Link] file: Ensure that you have
the following permissions in your [Link] to control WiFi and
Bluetooth:

[Link]

<uses-permission android:name="[Link]" />


<uses-permission android:name="[Link].BLUETOOTH_ADMIN" />
<uses-permission android:name="[Link].ACCESS_WIFI_STATE" />
<uses-permission android:name="[Link].CHANGE_WIFI_STATE" />

Java code

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

public class MainActivity extends AppCompatActivity

{ private WifiManager wifiManager;


private BluetoothAdapter bluetoothAdapter;
Mobile Application Development
private Switch wifiSwitch, bluetoothSwitch;
Mobile Application Development

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

wifiManager = (WifiManager)
getApplicationContext().getSystemService(Context.WIFI_SERVICE);
bluetoothAdapter = [Link]();

wifiSwitch = findViewById([Link]);
bluetoothSwitch = findViewById([Link]);

// Set initial state of switches


[Link]([Link]());
[Link]([Link]());

[Link](new
[Link]() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
toggleWiFi(isChecked);
}
});

[Link](new
[Link]() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
toggleBluetooth(isChecked);
}
});
}

private void toggleWiFi(boolean enable) {


if (enable) {
[Link](true);
} else {
[Link](false);
}
Mobile Application Development

private void toggleBluetooth(boolean enable)


{ if (enable) {
[Link]();
} else {
[Link]();
}
}
}

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:padding="16dp">

<Switch
android:id="@+id/wifiSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="WiFi"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />

<Switch
android:id="@+id/bluetoothSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bluetooth"
android:layout_below="@id/wifiSwitch"
android:layout_alignParentStart="true" />

</RelativeLayout>
Mobile Application Development

Practical No – 13
Develop android applications to demonstrate user interaction with the application using
Options Menu, Context Menu and Popup Menu.

Program – 1
To demonstrate user interaction with an Android application using the Options Menu

[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);
}

// Inflate the options menu


@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate([Link].options_menu, menu);
return true;
}

// Handle option menu item clicks


@Override
public boolean onOptionsItemSelected(MenuItem item)
{ switch ([Link]()) {
case [Link].menu_option_1:
showToast("Option 1 selected");
return true;
case [Link].menu_option_2:
showToast("Option 2
Mobile Application Development
selected");
Mobile Application Development

return true;
case [Link].menu_option_3:
showToast("Option 3 selected");
return true;
default:
return [Link](item);
}
}

private void showToast(String message) {


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

options_menu.xml
<!-- options_menu.xml -->
<menu xmlns:android="[Link]
<item
android:id="@+id/menu_option_1"
android:title="Option 1"
android:orderInCategory="100"
android:showAsAction="never" />
<item
android:id="@+id/menu_option_2"
android:title="Option 2"
android:orderInCategory="101"
android:showAsAction="never" />
<item
android:id="@+id/menu_option_3"
android:title="Option 3"
android:orderInCategory="102"
android:showAsAction="never" />
</menu>
Mobile Application Development

Program – 2
To demonstrate user interaction with an Android application using the context Menu.

activity_main.xml
<!-- activity_main.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"
android:orientation="vertical"
android:padding="16dp"
tools:context=".MainActivity">

<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>

context_menu.xml
<!-- context_menu.xml -->
<menu xmlns:android="[Link]
<item
android:id="@+id/action_edit"
android:title="Edit" />
<item
android:id="@+id/action_delete"
android:title="Delete" />
</menu>
Mobile Application Development

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

import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {

private ListView listView;


private ArrayAdapter<String> adapter;

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

listView = findViewById([Link]);

// Sample data for the ListView


String[] items = {"Item 1", "Item 2", "Item 3", "Item 4", "Item 5"};

adapter = new ArrayAdapter<>(this, [Link].simple_list_item_1, items);


[Link](adapter);

// Register the ListView for a context menu


registerForContextMenu(listView);
}

@Override
public void onCreateContextMenu(ContextMenu menu, View v,
[Link] menuInfo) {
[Link](menu, v, menuInfo);
Mobile Application Development

getMenuInflater().inflate([Link].context_menu, menu);
}

@Override
public boolean onContextItemSelected(@NonNull MenuItem item) {
// Handle context menu item selection
[Link] info = ([Link])
[Link]();
int position = [Link];
String selectedItem = [Link](position);

switch ([Link]())
{ case [Link].action_edit:
// Perform the edit action
[Link](this, "Edit: " + selectedItem, Toast.LENGTH_SHORT).show();
return true;
case [Link].action_delete:
// Perform the delete action
[Link](selectedItem);
[Link]();
[Link](this, "Deleted: " + selectedItem, Toast.LENGTH_SHORT).show();
return true;
default:
return [Link](item);
}
}
}

 Now, run the application on an Android emulator or a physical device.


 You should see a list of items.
 Long-press on an item and the context menu will appear with "Edit" and
"Delete" options.
 Selecting these options will display a toast message and delete the item from the
list, respectively.
Mobile Application Development

Program – 3
To demonstrate user interaction with an Android application using the Popup Menu.

activity_main.xml

<!-- activity_main.xml -->


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

<Button
android:id="@+id/btnShowPopup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Popup Menu"
android:layout_centerInParent="true" />

<TextView
android:id="@+id/tvSelectedOption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/btnShowPopup"
android:layout_centerHorizontal="true"
android:paddingTop="16dp" />

</RelativeLayout>

[Link]

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
Mobile Application Development
Mobile Application Development

import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {

private Button btnShowPopup;


private TextView
tvSelectedOption;

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

btnShowPopup = findViewById([Link]);
tvSelectedOption =
findViewById([Link]);

[Link](new [Link]() {
@Override
public void onClick(View v) {
// Create and show the Popup Menu
showPopupMenu();
}
});
}

private void showPopupMenu() {


// Create a PopupMenu object with the anchor view (the button) as the first parameter
PopupMenu popupMenu = new PopupMenu(this, btnShowPopup);

// Inflate the menu layout from the XML resource file


[Link]().inflate([Link].popup_menu, [Link]());

// Set a click listener on the Popup Menu items


[Link](new [Link]()
{
@Override
public boolean onMenuItemClick(MenuItem item) {
// Handle the selected item here
Mobile Application Development
String selectedOption = [Link]().toString();
Mobile Application Development

[Link]("Selected: " +
selectedOption); return true;
}
});

// Show the Popup Menu


[Link]();
}
}

popup_menu.xml

<!-- res/menu/popup_menu.xml -->


<menu xmlns:android="[Link]
<item
android:id="@+id/option1"
android:title="Option 1" />
<item
android:id="@+id/option2"
android:title="Option 2" />
<item
android:id="@+id/option3"
android:title="Option 3" />
</menu>

 Build and run the application on an Android emulator or physical device.


 When you click the "Show Popup Menu" button, the Popup Menu will appear with
the three options ("Option 1," "Option 2," and "Option 3").
 When you select an option from the menu, the selected option will be displayed
below the button in the TextView.
Mobile Application Development

Practical – 14

Develop Android Applications to demonstrate different AlertDialogs and the Custom


Dialog.

Program – 1

To demonstrate AlertDialog in Android applications

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:orientation="vertical"
android:padding="16dp"
tools:context=".MainActivity">

<Button
android:id="@+id/btnShowDialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Dialog" />
</LinearLayout>

[Link]

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

import [Link];
import [Link];
Mobile Application Development
public class MainActivity extends AppCompatActivity {
Mobile Application Development

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

Button btnShowDialog = findViewById([Link]);


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

private void showAlertDialog() {


// Basic AlertDialog
new [Link](this)
.setTitle("Basic AlertDialog")
.setMessage("This is a basic AlertDialog.")
.setPositiveButton("OK", null)
.show();

// Confirmation AlertDialog
new [Link](this)
.setTitle("Confirmation AlertDialog")
.setMessage("Do you want to proceed?")
.setPositiveButton("Yes", new [Link]() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Code to handle positive button click
}
})
.setNegativeButton("No", new [Link]() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Code to handle negative button click
}
})
.show();
Mobile Application Development

// List AlertDialog
final String[] items = {"Item 1", "Item 2", "Item 3"};
new [Link](this)
.setTitle("List AlertDialog")
.setItems(items, new [Link]() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Code to handle item selection
}
})
.show();
}
}

Program – 2

To demonstrate Custom Dialog in Android applications.

custom_dialog_layout.xml

<!-- custom_dialog_layout.xml -->


<LinearLayout
xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">

<TextView
android:id="@+id/dialogTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Custom Dialog"
android:textSize="18sp"
android:textColor="@android:color/black"
android:gravity="center"/>

<!-- Add other views as per your requirement -->


Mobile Application Development

<Button
android:id="@+id/dialogButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Close"
android:textColor="@android:color/white"
android:background="@drawable/button_background"/>

</LinearLayout>

 Create a new Java or Kotlin class that extends the Dialog class to create a
custom dialog.

Java Code:

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

public class CustomDialog extends Dialog

{ private String title;


private OnDialogButtonClickListener onDialogButtonClickListener;

public CustomDialog(Context context, String title) {


super(context);
[Link] = title;
}

public void setOnDialogButtonClickListener(OnDialogButtonClickListener listener)


{ [Link] = listener;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
Mobile Application Development

setContentView([Link].custom_dialog_layout);

TextView dialogTitle = findViewById([Link]);


Button dialogButton = findViewById([Link]);

[Link](title);

[Link](v -> {
if (onDialogButtonClickListener != null) {
[Link]();
}
dismiss();
});
}

public interface OnDialogButtonClickListener


{ void onDialogButtonClick();
}
}

 Use the Custom Dialog in your activity: In your activity, use the custom dialog
class to show the dialog when needed. You can trigger the custom dialog to appear
when a button is clicked

Java Code:

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

public class MainActivity extends AppCompatActivity {

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

findViewById([Link]).setOnClickListener(v ->
showCustomDialog());
}
Mobile Application Development

private void showCustomDialog() {


CustomDialog customDialog = new CustomDialog(this, "Custom Dialog Example");
[Link](() -> {
// Handle button click action
// For example, perform some operation or close the dialog
});
[Link]();
}
}

 In this example, when the button with the ID showCustomDialogButton is clicked, the
custom dialog will be displayed with the provided title.
 The OnDialogButtonClickListener interface allows you to handle button click actions
inside the custom dialog.
 Remember to replace [Link].activity_main with your activity's layout file, and
make sure to have the custom dialog layout XML available in the res/layout directory.
Mobile Application Development

Practical No – 15

Develop Android Application for local database connectivity and performing basic
database operations (select, insert, update, delete) using SQLiteDatabase and
SQLiteOpenHelper Classes.

1. In the XML layout file (e.g., activity_main.xml), create the necessary UI elements like
EditText and Buttons to perform database operations.
2. Create a new Java class called DatabaseHelper. This class will extend
SQLiteOpenHelper and handle creating and managing the database.

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

public class DatabaseHelper extends SQLiteOpenHelper {


private static final String DATABASE_NAME = "my_database";
private static final int DATABASE_VERSION = 1;

private static final String TABLE_NAME = "my_table";


private static final String COLUMN_ID = "_id";
private static final String COLUMN_NAME = "name";
// Add other columns as needed

private static final String CREATE_TABLE_QUERY = "CREATE TABLE "


+ TABLE_NAME + " (" +
COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
COLUMN_NAME + " TEXT NOT NULL);";

public DatabaseHelper(Context context) {


super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

@Override
public void onCreate(SQLiteDatabase db) {
[Link](CREATE_TABLE_QUERY);
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Mobile Application Development

[Link]("DROP TABLE IF EXISTS " + TABLE_NAME);


onCreate(db);
}
}

[Link]

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

import [Link];

public class MainActivity extends AppCompatActivity implements [Link]


{ private DatabaseHelper databaseHelper;
private EditText nameEditText;
private Button insertButton, selectButton, updateButton, deleteButton;

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

databaseHelper = new DatabaseHelper(this);

nameEditText = findViewById([Link]);
insertButton = findViewById([Link]);
selectButton = findViewById([Link]);
updateButton = findViewById([Link]);
deleteButton = findViewById([Link]);

[Link](this);
[Link](this);
[Link](this);
[Link](this);
Mobile Application Development

@Override
public void onClick(View v) {
switch ([Link]()) {
case [Link]:
insertData();
break;
case [Link]:
selectData();
break;
case [Link]:
updateData();
break;
case [Link]:
deleteData();
break;
}
}

private void insertData() {


String name = [Link]().toString().trim();

if (![Link]()) {
SQLiteDatabase db = [Link]();

ContentValues values = new ContentValues();


[Link](DatabaseHelper.COLUMN_NAME, name);

long rowId = [Link](DatabaseHelper.TABLE_NAME, null, values);

if (rowId != -1) {
[Link](this, "Data inserted successfully", Toast.LENGTH_SHORT).show();
} else {
[Link](this, "Failed to insert data", Toast.LENGTH_SHORT).show();
}

[Link]();
}
}
Mobile Application Development

private void selectData() {


SQLiteDatabase db = [Link]();

Cursor cursor = [Link](DatabaseHelper.TABLE_NAME, null, null, null, null, null,


null);

StringBuilder data = new StringBuilder();


while ([Link]()) {
int id = [Link]([Link](DatabaseHelper.COLUMN_ID));
String name =
[Link]([Link](DatabaseHelper.COLUMN_NAME));

[Link]("ID: ").append(id).append(", Name: ").append(name).append("\n");


}

[Link]();
[Link]();

[Link](this, [Link](), Toast.LENGTH_SHORT).show();


}

private void updateData() {


// Implement update operation
}

private void deleteData() {


// Implement delete operation
}
}
Mobile Application Development

Practical No – 17

Develop an Android Application to demonstrate the use of RecyclerView and CardView


for displaying list of items with multiple information.

Note: target a minimum SDK version that supports RecyclerView and CardView (at least API
level 21).

1. In your app's [Link] file, add the following dependencies:

implementation '[Link]:recyclerview:1.1.0'
implementation '[Link]:cardview:1.0.0'

2. Create a model class to represent the items that will be displayed in the

list. public class Item {


private String title;
private String description;
// Add more fields as needed

public Item(String title, String description)


{ [Link] = title;
[Link] = description;
}

// Create getters and setters as needed


}

3. Create an adapter class that extends [Link] to handle the item list
and bind the data to the CardView layout.

public class ItemAdapter extends [Link]<[Link]>


{ private List<Item> itemList;

public ItemAdapter(List<Item> itemList)


{ [Link] = itemList;
}

@NonNull
@Override
Mobile Application Development

public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int


viewType) {
View view = [Link]([Link]()).inflate([Link].item_layout,
parent, false);
return new ItemViewHolder(view);
}

@Override
public void onBindViewHolder(@NonNull ItemViewHolder holder, int position)
{ Item item = [Link](position);
[Link]([Link]());
[Link]([Link]());
// Bind more data to the CardView as needed
}

@Override
public int getItemCount() {
return [Link]();
}

public static class ItemViewHolder extends [Link]


{ TextView titleTextView;
TextView descriptionTextView;
// Add more views from your CardView layout

public ItemViewHolder(View itemView) {


super(itemView);
titleTextView = [Link]([Link]);
descriptionTextView =
[Link]([Link]);
// Initialize other views from your CardView layout
}
}
}

4. Create the layout file for your RecyclerView activity (e.g., activity_main.xml) with a
RecyclerView.

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


<RelativeLayout
xmlns:android="[Link]
Mobile Application Development
Mobile Application Development

android:layout_width="match_parent"
android:layout_height="match_parent">

<[Link]
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>

5. Create the layout file for the CardView item (e.g., item_layout.xml) that will display the
information for each item in the list. Customize this layout as per your requirements.

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


<[Link]
xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">

<TextView
android:id="@+id/titleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textStyle="bold"/>

<TextView
android:id="@+id/descriptionTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="14sp"/>
<!-- Add more views for other information -->

</LinearLayout>
Mobile Application Development

</[Link]>

6. In the [Link], initialize the RecyclerView, create a list of items, and set up
the RecyclerView with the custom adapter:

public class MainActivity extends AppCompatActivity {

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

RecyclerView recyclerView = findViewById([Link]);


[Link](new LinearLayoutManager(this));

List<Item> itemList = createItemList(); // Replace this with your own logic to create
the list of items
ItemAdapter itemAdapter = new ItemAdapter(itemList);
[Link](itemAdapter);
}

private List<Item> createItemList() {


// Replace this with your own logic to create a list of items
List<Item> itemList = new ArrayList<>();
[Link](new Item("Item 1", "Description for Item
1")); [Link](new Item("Item 2", "Description for
Item 2"));
// Add more items as needed
return itemList;
}
}
Mobile Application Development
Develop a simple application to display “Hello <Application Name>” using Kotlin

1. Create a new Kotlin project in your preferred IDE.


2. If you're using IntelliJ IDEA or Android Studio, you can create a new Kotlin project by
selecting "File" > "New" > "Project" > "Kotlin" > "Kotlin JVM."
3. In the main Kotlin file (usually named "[Link]"), add the following code:

[Link]

fun main()
{
val applicationName = "My Simple Kotlin App"
println("Hello $applicationName")
}

Prepared By: VPMP Polytechnic, Department of Computer Engineering Page 65


Practical No – 19
Develop an android application using Kotlin having a Button “Click” and upon clicking
on that Button a Toast message “Button Clicked” should be displayed on screen through
Toast Message

activity_main.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"
android:orientation="vertical"
android:padding="16dp"
tools:context=".MainActivity">

<Button
android:id="@+id/buttonClick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click" />
</LinearLayout>

[Link]

package [Link] // Replace with your actual package name

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

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {


[Link](savedInstanceState)
setContentView([Link].activity_main)

// Find the button by its ID

Page 66
val buttonClick = findViewById<Button>([Link])

// Set click listener on the button


[Link] {
// Display a toast message when the button is clicked
showToastMessage("Button Clicked")
}
}

// Function to show a toast message


private fun showToastMessage(message: String)
{ [Link](this, message,
Toast.LENGTH_SHORT).show()
}
}

Page 67
Page 68
Practical No – 20

Publish an Android Application on Play Store

Publishing an Android application on the Google Play Store involves several steps. Here's
a step-by-step guide to help you through the process:

1. Prepare your App:


 Ensure that your Android app is fully developed, tested, and ready for public use.
 Optimize the app for different screen sizes and orientations.

2. Create a Developer Account:


 Go to the Google Play Developer Console
([Link] and sign in with your Google account.
 Pay the one-time registration fee (at the time of writing this, it was $25) to
create your developer account.

3. Prepare Store Listing:


 Provide essential details about your app, such as the app's title,
description, screenshots, promotional graphics, and a high-resolution app
icon.
 Write an informative and compelling description for your app to attract potential
users.
 Choose appropriate categories and tags to help users discover your app.

4. Set Pricing & Distribution:


 Decide whether you want to offer your app for free or set a price.
 Select the countries where you want your app to be available.
 Decide if you want to limit the availability to specific devices or if the app
is compatible with all Android devices.

5. Upload APK (Android Package) or App Bundle:


 Build a signed APK or an Android App Bundle that's ready for distribution.
 In the Developer Console, navigate to the "App releases" section and follow
the steps to upload your APK or App Bundle.

6. App Content Rating:


 Complete the content rating questionnaire to classify your app's content and set
an appropriate age rating.

Page 69
Page 70
7. Opt-in to App Signing:
 Google Play now encourages developers to use App Signing. If you opt-in,
Google will manage the signing key for you.
 Upload your signing key or create a new one using Google's App Signing service.

8. Review & Publish:


 Once you've completed all the necessary steps and uploaded your APK or
App Bundle, submit your app for review.
 Google Play will review your app to ensure it meets their policies and guidelines.
 This review process may take a few hours to several days, depending on
various factors.

9. Launch Your App:


 Once your app is approved, you can choose to launch it immediately or schedule
a specific date for the release.
 The app will be available to users on the Google Play Store after it's published.

[Link] & Update:


 Keep an eye on user feedback and analytics to understand your app's performance.
 Regularly update your app to fix bugs, add new features, and improve
user experience.

Page 71

You might also like