Android Program-Solution
Android Program-Solution
Practical No– 01
Set-up of Android development environment, managing AVD and understanding its
various components.
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
activity_main.xml
<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
[Link]
import [Link];
import [Link];
import [Link];
import [Link];
@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
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
<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.
<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>
<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>
<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]>
<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
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
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
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];
@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!");
}
}
});
@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;
}
}
});
}
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];
@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];
@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.
<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
<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];
@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];
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_settings);
etName = findViewById([Link]);
etEmail = findViewById([Link]);
btnSave = findViewById([Link]);
[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
}
});
}
}
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];
@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);
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{ String selectedItem = [Link](position);
[Link]([Link], "Selected item: " + selectedItem,
Toast.LENGTH_SHORT).show();
}
});
}
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];
@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");
[Link]([Link].simple_spinner_dropdown_item)
;
[Link](spinnerAdapter);
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
[Link]().clear();
}
}
});
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
[Link] code
<manifest xmlns:android="[Link]
package="[Link]">
<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];
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
}
}
Program – 2
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]
Java code
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@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]);
[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);
}
});
}
activity_main.xml
<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];
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
}
return true;
case [Link].menu_option_3:
showToast("Option 3 selected");
return true;
default:
return [Link](item);
}
}
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];
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
listView = findViewById([Link]);
@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);
}
}
}
Program – 3
To demonstrate user interaction with an Android application using the Popup Menu.
activity_main.xml
<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];
@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();
}
});
}
[Link]("Selected: " +
selectedOption); return true;
}
});
popup_menu.xml
Practical – 14
Program – 1
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);
// 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
custom_dialog_layout.xml
<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"/>
<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];
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
Mobile Application Development
setContentView([Link].custom_dialog_layout);
[Link](title);
[Link](v -> {
if (onDialogButtonClickListener != null) {
[Link]();
}
dismiss();
});
}
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];
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
findViewById([Link]).setOnClickListener(v ->
showCustomDialog());
}
Mobile Application Development
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];
@Override
public void onCreate(SQLiteDatabase db) {
[Link](CREATE_TABLE_QUERY);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Mobile Application Development
[Link]
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
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;
}
}
if (![Link]()) {
SQLiteDatabase db = [Link]();
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
[Link]();
[Link]();
Practical No – 17
Note: target a minimum SDK version that supports RecyclerView and CardView (at least API
level 21).
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
3. Create an adapter class that extends [Link] to handle the item list
and bind the data to the CardView layout.
@NonNull
@Override
Mobile Application Development
@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]();
}
4. Create the layout file for your RecyclerView activity (e.g., activity_main.xml) with a
RecyclerView.
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.
<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:
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
List<Item> itemList = createItemList(); // Replace this with your own logic to create
the list of items
ItemAdapter itemAdapter = new ItemAdapter(itemList);
[Link](itemAdapter);
}
[Link]
fun main()
{
val applicationName = "My Simple Kotlin App"
println("Hello $applicationName")
}
activity_main.xml
<Button
android:id="@+id/buttonClick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click" />
</LinearLayout>
[Link]
import [Link]
import [Link]
import [Link]
import [Link]
Page 66
val buttonClick = findViewById<Button>([Link])
Page 67
Page 68
Practical No – 20
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:
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.
Page 71