Android Assignment
Android Assignment
Date: _________
Certificate
This is to certify that Mr. ___________________________ seat no ___________of BCA
Semester-VI has completed the practical work in the subject of Current Trends in IT
during the academic year 2023–2024 under the guidance of Prof. Kamalam Sundarrajan
being the partial requirement for the fulfillment of the curriculum of Degree of Bachelor
of Computer Application, University of Tilak Maharashtra Vidyapeeth.
.
College Seal
INDEX
1 Assignment 1
2 Assignment 2
3 Assignment 3
4 Assignment 4
5 Assignment 5
6 Assignment 6
7 Assignment 7
8 Assignment 8
Assignment 1
Create a mobile app containing 2 EditTexts for username and password, 1 CheckBox for
course selection, RadioButtons for gender and Register Button. On click of Register Button,
display username, password, course selection & selected gender using Toast?
activity_main.xml:-
<LinearLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#292F50"
android:orientation="vertical"
android:padding="16dp">
<EditText
android:id="@+id/usernameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username" />
<EditText
android:id="@+id/passwordEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="30dp"
android:hint="Password"
android:inputType="textPassword" />
<CheckBox
android:id="@+id/courseCheckBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BCA" />
<CheckBox
android:id="@+id/courseCheckBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="MCA" />
<CheckBox
android:id="@+id/courseCheckBox3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="30dp"
android:text="MBA" />
<RadioGroup
android:id="@+id/genderRadioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="@+id/maleRadioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male" />
<RadioButton
android:id="@+id/femaleRadioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female" />
</RadioGroup>
<Button
android:id="@+id/registerButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:text="Register" />
</LinearLayout>
Content_main.xml:-
[Link]:-
package [Link].apk1;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
Output :-
Assignment 2
Create a mobile app containing EditText (for accepting string from user), 2 RadioButtons
([Link]-CASE, [Link]-case) and Show Button. Perform selected operation on the string in
EditText & display result on the same page using Toast.
activity_main.xml:-
<LinearLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#1E2130"
android:orientation="vertical"
android:padding="16dp">
<EditText
android:id="@+id/inputEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter a string" />
<RadioGroup
android:id="@+id/caseRadioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="@+id/upperRadioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="UPPER-CASE" />
<RadioButton
android:id="@+id/lowerRadioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="lower-case" />
</RadioGroup>
<Button
android:id="@+id/showButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show" />
</LinearLayout>
[Link]:-
package [Link].apk2;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
EditText inputEditText;
RadioGroup caseRadioGroup;
Button showButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
inputEditText = findViewById([Link]);
caseRadioGroup = findViewById([Link]);
showButton = findViewById([Link]);
[Link](new [Link]() {
@Override
public void onClick(View v) {
String inputString = [Link]().toString();
int checkedId = [Link]();
RadioButton selectedRadioButton = findViewById(checkedId);
if (selectedRadioButton != null) {
String caseOption = [Link]().toString();
if ([Link]("UPPER-CASE")) {
inputString = [Link]();
} else if ([Link]("lower-case")) {
inputString = [Link]();
}
[Link]([Link], "Result: " + inputString,
Toast.LENGTH_SHORT).show();
} else {
[Link]([Link], "Please select an option",
Toast.LENGTH_SHORT).show();
}
}
});
}
}
Output :-
Assignment 3
Create a mobile app containing 3 checkboxes for different menus. When user selects any
menu or all menus, generate a bill with selected menus along with their quantity using
toast.
activity_main.xml:-
<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">
<LinearLayout
android:id="@+id/menu1Layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:visibility="visible">
<CheckBox
android:id="@+id/checkBoxMenu1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Paneer with Roti" />
<EditText
android:id="@+id/quantityMenu1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:layout_weight="1"
android:hint="Quantity"
android:inputType="number" />
</LinearLayout>
<LinearLayout
android:id="@+id/menu2Layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:visibility="visible">
<CheckBox
android:id="@+id/checkBoxMenu2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Gajar ka Halwa" />
<EditText
android:id="@+id/quantityMenu2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="60dp"
android:layout_weight="1"
android:hint="Quantity"
android:inputType="number" />
</LinearLayout>
<LinearLayout
android:id="@+id/menu3Layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:visibility="visible">
<CheckBox
android:id="@+id/checkBoxMenu3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Litti Chokha" />
<EditText
android:id="@+id/quantityMenu3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="75dp"
android:layout_weight="1"
android:hint="Quantity"
android:inputType="number" />
</LinearLayout>
<Button
android:id="@+id/btnGenerateBill"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Generate Bill" />
</LinearLayout>
content_main.xml:-
<TextView
android:id="@+id/toastText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:text="This is a custom toast message"
android:textColor="#FFFFFF"
android:textSize="20sp" />
</LinearLayout>
[Link]:-
package [Link].apk3;
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);
menu1CheckBox = findViewById([Link].checkBoxMenu1);
menu2CheckBox = findViewById([Link].checkBoxMenu2);
menu3CheckBox = findViewById([Link].checkBoxMenu3);
generateBillButton = findViewById([Link]);
[Link](new [Link]() {
@Override
public void onClick(View v) {
StringBuilder bill = new StringBuilder();
int totalAmount = 0;
if ([Link]()) {
[Link]("Paneer with Roti: ");
int quantity =
[Link](((TextView)findViewById([Link].quantityMenu1)).getText().toString());
[Link](quantity + " x 300rs = " + (quantity * 300) + "rs\n");
totalAmount += quantity * 300;
}
if ([Link]()) {
[Link]("Gajar ka Halwa : ");
int quantity =
[Link](((TextView)findViewById([Link].quantityMenu2)).getText().toString());
[Link](quantity + " x 150rs = " + (quantity * 150) + "rs\n");
totalAmount += quantity * 150;
}
if ([Link]()) {
[Link]("Litti Chokha: ");
int quantity =
[Link](((TextView)findViewById([Link].quantityMenu3)).getText().toString());
[Link](quantity + " x 450rs = " + (quantity * 450) + "rs\n");
totalAmount += quantity * 450;
}
if ([Link]() > 0) {
View layout = getLayoutInflater().inflate([Link].content_main, null);
TextView text = [Link]([Link]);
[Link]("--------------------------");
[Link]("\nTotal Amount: Rs " + totalAmount);
[Link](bill);
[Link](bill);
Toast toast = new Toast(getApplicationContext());
[Link](Toast.LENGTH_LONG);
[Link](layout);
[Link]();
} else {
[Link]([Link], "Please select at least one menu",
Toast.LENGTH_SHORT).show();
}
}
});
}
}
Output :-
Assignment 4
Create a mobile app containing ListView having a list of courses. On click of any course,
subjects related to that course should display in spinner. For eg. For BCA course- C,C++,
Java, For BCom course- Accounts, PPM, Economics. When user selects BCA from
listview-subjects related to BCA should appear in spinner.
activity_main.xml:-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/coursesListView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
content_main.xml:-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp">
<TextView
android:id="@+id/courseTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceListItem"
android:textSize="18sp"/>
<Spinner
android:id="@+id/subjectsSpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"/>
</LinearLayout>
[Link]:-
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [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);
coursesListView = findViewById([Link]);
initializeSubjectsMap();
populateCoursesListView();
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
View itemView = convertView;
if (itemView == null) {
itemView = [Link](getContext()).inflate([Link].content_main, parent, false);
}
if (course != null) {
[Link](course);
[Link](new [Link]() {
@Override
public void onClick(View v) {
if ([Link]() == [Link]) {
[Link]([Link]);
} else {
[Link]([Link]);
}
}
});
[Link]([Link].simple_spinner_dropdown_item);
[Link](spinnerAdapter);
[Link](new [Link]()
{
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
{
String selectedSubject = (String) [Link](position);
[Link]([Link], "Selected subject for " + course + ": " +
selectedSubject, Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// Do nothing
}
});
}
}
return itemView;
}
}
}
Output :-
Assignment 5
Create a mobile app containing ListView having a list of countries. On click of any country in
the listview, country's flag should display in ImageView.
activity_main.xml:-
<RelativeLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ListView
android:id="@+id/countriesListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="16dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"/>
<ImageView
android:id="@+id/flagImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@mipmap/india_flag"
android:visibility="gone"/>
</RelativeLayout>
[Link]:-
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
Output :-
Assignment 6
Create a mobile app containing 2 EditTexts for username and password. When user clicks on
submit show it to the next Activity.
Activity_main.xml:-
<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">
<EditText
android:id="@+id/editTextUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="150dp"
android:hint="Username" />
<EditText
android:id="@+id/editTextPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword" />
<Button
android:id="@+id/buttonSubmit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="50dp"
android:text="Submit" />
</LinearLayout>
Content_main.xml:-
<LinearLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">
<TextView
android:id="@+id/usernameTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="@+id/passwordTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
[Link]:-
package [Link].apk4;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
editTextUsername = findViewById([Link]);
editTextPassword = findViewById([Link]);
buttonSubmit = findViewById([Link]);
[Link](new [Link]() {
@Override
public void onClick(View v) {
String username = [Link]().toString().trim();
String password = [Link]().toString().trim();
Intent intent = new Intent([Link], [Link]);
[Link]("USERNAME", username);
[Link]("PASSWORD", password);
startActivity(intent);
}
});
}
}
[Link] :-
package [Link].apk4;
import [Link];
import [Link];
import [Link];
import [Link];
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].content_main);
textViewUsername = findViewById([Link]);
textViewPassword = findViewById([Link]);
Intent intent = getIntent();
if (intent != null) {
String username = [Link]("USERNAME");
String password = [Link]("PASSWORD");
[Link]("Username: " + username);
[Link]("Password: " + password);
}
}
}
Output :-
Assignment 7
Designn a mobile application for music player using android services.
Activity_main.xml:-
<TextView
android:id="@+id/tvSongTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Current Song Title"
android:textSize="18sp"
android:layout_centerHorizontal="true"
android:layout_marginBottom="16dp">
<Button
android:id="@+id/btnPrevious"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Previous"
android:layout_below="@id/tvSongTitle"
android:layout_alignParentStart="true"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"/>
<Button
android:id="@+id/btnPlayPause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Play"
android:layout_below="@id/tvSongTitle"
android:layout_centerHorizontal="true"
android:layout_marginBottom="8dp"/>
<Button
android:id="@+id/btnNext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Next"
android:layout_below="@id/tvSongTitle"
android:layout_alignParentEnd="true"
android:layout_marginStart="8dp"
android:layout_marginBottom="8dp"/>
</RelativeLayout>
[Link]:-
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
[Link](new [Link]() {
@Override
public void onClick(View v) {
playPauseSong();
}});
[Link](new [Link]() {
@Override
public void onClick(View v) {
playPreviousSong();
}});
[Link](new [Link]() {
@Override
public void onClick(View v) {
playNextSong();
}});}
private void playPauseSong() {
if ([Link]()) {
[Link]();
} else {
[Link]();
}}
private void playNextSong() {
if (currentSongIndex < [Link]() - 1) {
currentSongIndex++;
[Link]();
mediaPlayer = [Link](this, [Link](currentSongIndex));
[Link]();
updateSongTitle();
} else {
[Link](this, "No more songs", Toast.LENGTH_SHORT).show();
}}
@Override
protected void onDestroy() {
[Link]();
if (mediaPlayer != null) {
[Link]();
mediaPlayer = null;
}}}
Output :-
Assignment 8
Create a mobile app for storing username and phone number using database. And display all
records using toast.
Activity_main.xml:-
<EditText
android:id="@+id/editTextName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:hint="Enter Name" />
<EditText
android:id="@+id/editTextPhone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Phone Number"
android:inputType="phone" />
<Button
android:id="@+id/btnAddUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="addUser"
android:text="+ Add User" />
<Button
android:id="@+id/btnShowUsers"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="50dp"
android:onClick="showUsers"
android:text="Show Users" />
</LinearLayout>
Custom_toast.xml:-
<TextView xmlns:android="[Link]
android:id="@+id/textViewMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#AA000000"
android:textColor="@android:color/white"
android:textSize="16sp"
android:textStyle="bold"
android:padding="16dp" />
[Link]:-
package [Link].apk7;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
private EditText editTextName, editTextPhone;
private DBHandler dbHandler;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
editTextName = findViewById([Link]);
editTextPhone = findViewById([Link]);
dbHandler = new DBHandler(this);
}
public void addUser(View view) {
String name = [Link]().toString().trim();
String phone = [Link]().toString().trim();
if (![Link]() && ![Link]()) {
int id = generateUserId();
User user = new User(id, name, phone);
[Link](user);
[Link](this, "User added to database",
Toast.LENGTH_SHORT).show();
[Link]("");
[Link]("");
} else {
[Link](this, "Please enter name and phone number",
Toast.LENGTH_SHORT).show();
}}
private int userIdCounter = 1;
private int generateUserId() {
return userIdCounter++;
}
private int getNextUserIdFromDatabase() {
return userIdCounter;
}
public void showUsers(View view) {
Cursor cursor = [Link]();
if (cursor != null && [Link]()) {
StringBuilder usersText = new StringBuilder();
int nameIndex = [Link](DBHandler.NAME_COL);
int phoneIndex = [Link](DBHandler.PHONE_COL);
do {
String name = [Link](nameIndex);
String phone = [Link](phoneIndex);
[Link]("Name: ").append(name).append("\n Phone:
").append(phone).append("\n\n\n");
} while ([Link]());
[Link]();
showToast([Link]());
} else {
showToast("No users found");
} }
private void showToast(String message) {
View toastView =
getLayoutInflater().inflate([Link].custom_toast, null);
TextView textViewMessage = [Link]([Link]);
[Link](message);
Toast toast = new Toast(this);
[Link](toastView);
[Link](Toast.LENGTH_LONG);
[Link]();
}}
[Link]:-
package [Link].apk7;
public class User {
private int id;
private String name;
private String phone;
public User(int id, String name, String phone) {
[Link] = id;
[Link] = name;
[Link] = phone;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public String getPhone() {
return phone;
}}
[Link]
package [Link].apk7;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class DBHandler extends SQLiteOpenHelper {
private static final String DB_NAME = "userdb";
private static final int DB_VERSION = 1;
private static final String TABLE_NAME = "users";
private static final String ID_COL = "id";
public static final String NAME_COL = "name";
public static final String PHONE_COL = "phone";
public DBHandler(Context context) {
super(context, DB_NAME, null, DB_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
String query = "CREATE TABLE " + TABLE_NAME + " (" + ID_COL + " INTEGER
PRIMARY KEY AUTOINCREMENT, " + NAME_COL + " TEXT, " + PHONE_COL + " TEXT)";
[Link](query);
}
public void addUser( User user) {
SQLiteDatabase db = [Link]();
ContentValues values = new ContentValues();
[Link](NAME_COL, [Link]());
[Link](PHONE_COL, [Link]());
[Link](TABLE_NAME, null, values);
[Link]();
}
public Cursor getAllUsers() {
SQLiteDatabase db = [Link]();
String[] projection = {ID_COL, NAME_COL, PHONE_COL};
return [Link](TABLE_NAME, projection, null, null, null, null,
null);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int
newVersion) {
[Link]("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}}
Output :-