0% found this document useful (0 votes)
13 views57 pages

Android App for Factorial Calculation

The document outlines several Android programming tasks, including creating applications to calculate factorials, manage student data, send notifications, and demonstrate ListView functionality. Each task includes XML layout files and Java code for implementing the desired features. The applications involve user input, data display, and interaction through buttons and alerts.

Uploaded by

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

Android App for Factorial Calculation

The document outlines several Android programming tasks, including creating applications to calculate factorials, manage student data, send notifications, and demonstrate ListView functionality. Each task includes XML layout files and Java code for implementing the desired features. The applications involve user input, data display, and interaction through buttons and alerts.

Uploaded by

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

ANDROID PROGRAM SLIPS

20 Marks

Slip 3. Create an Android Application to find the factorial of a number and Display the Result
on Alert Box.

XML FILE
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:gravity="center"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Factorial of Number"
android:textSize="30dp"
/>

<EditText
android:layout_width="298dp"
android:layout_height="58dp"
android:hint="Enter the number"
android:id="@+id/input" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Calculate"
android:id="@+id/cal" />
</LinearLayout>
JAVA FILE
package [Link].slip3b1;

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];

public class MainActivity extends AppCompatActivity {

@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
[Link](this);
setContentView([Link].activity_main);
[Link](findViewById([Link]), (v, insets) -> {
Insets systemBars = [Link]([Link]());
[Link]([Link], [Link], [Link], [Link]);
return insets;
});

Button b;
EditText num;
b=(Button) findViewById([Link]);
num=(EditText) findViewById([Link]);

[Link] builder;
builder = new [Link]([Link]);

[Link](new [Link]() {
@Override
public void onClick(View view) {
double i,n,fact=1;
n=[Link]([Link]().toString());
for(i=1;i<=n;i++) {
fact=fact*i;
}
[Link]("Factorial of Number: ")
.setMessage("Factorial = "+fact)
.setPositiveButton("Yes", new [Link]() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
finish();;
}
})
.setNegativeButton("No", new [Link]() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
[Link]();
}
})
.show();
}
});
}
}

(or)Slip 3. Create an Android App, it reads the Students Details (Name, Surname, Class,
Gender, Hobbies, Marks) and display the all information in another activity in table format
on click of Submit button.
Slip 11. Create First Activity to accept information like Student First Name, Middle Name,
Last Name, Date of birth, Address, Email ID and display all information on Second Activity
when user click on the Submit button.
Slip 15. Create First Activity to accept information like Employee First Name, Middle Name,
Last Name, Salary, Address, Email ID and display all information on Second Activity when
user click on Submit button.

XML FILE 1
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/arbutus"
android:text="Student Data!"
android:textSize="40dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<EditText
android:id="@+id/fname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Name"
android:textSize="30dp" />

<EditText
android:id="@+id/mname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Surname"
android:textSize="30dp" />

<EditText
android:id="@+id/lname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Class"
android:textSize="30dp" />

<EditText
android:id="@+id/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Gender"
android:textSize="30dp" />

<EditText
android:id="@+id/Date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Hobbies"
android:textSize="30dp" />

<EditText
android:id="@+id/EmailAddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Marks"
android:textSize="30dp" />

<Button
android:id="@+id/button"
android:layout_width="112dp"
android:layout_height="wrap_content"
android:textSize="20dp"
android:text="Button" />

</LinearLayout>

JAVA FILE 1
package [Link];

import [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 {

@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
[Link](this);
setContentView([Link].activity_main);
[Link](findViewById([Link]), (v, insets) -> {
Insets systemBars = [Link]([Link]());
[Link]([Link], [Link], [Link], [Link]);
return insets;
});

Button b1;
EditText f1,m1,l1,d1,a1,e1;

b1=(Button) findViewById([Link]);
f1=(EditText) findViewById([Link]);
m1=(EditText) findViewById([Link]);
l1=(EditText) findViewById([Link]);
d1=(EditText) findViewById([Link]);
a1=(EditText) findViewById([Link]);
e1=(EditText) findViewById([Link]);

[Link](new [Link]() {
@Override
public void onClick(View v) {
String fir,sec,thi,dob,addr,id;
fir=[Link]().toString();
sec=[Link]().toString();
thi=[Link]().toString();
dob=[Link]().toString();
addr=[Link]().toString();
id=[Link]().toString();

Intent intent=new Intent([Link], [Link]);


[Link]("name",fir);
[Link]("surname",sec);
[Link]("class",thi);
[Link]("gender",dob);
[Link]("hobbies",addr);
[Link]("marks",id);

startActivity(intent);
}
});

}
}

XML FILE 2
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:orientation="vertical"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity2">

<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="1">

<TableRow>
<TextView android:text="Name:"/>
<TextView android:id="@+id/tvName"/>
</TableRow>

<TableRow>
<TextView android:text="Surname:"/>
<TextView android:id="@+id/tvSurname"/>
</TableRow>

<TableRow>
<TextView android:text="Class:"/>
<TextView android:id="@+id/tvClass"/>
</TableRow>
<TableRow>
<TextView android:text="Gender:"/>
<TextView android:id="@+id/tvGender"/>
</TableRow>

<TableRow>
<TextView android:text="Hobbies:"/>
<TextView android:id="@+id/tvHobbies"/>
</TableRow>

<TableRow>
<TextView android:text="Marks:"/>
<TextView android:id="@+id/tvMarks"/>
</TableRow>

</TableLayout>

</LinearLayout>

JAVA FILE 2
package [Link];

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

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

public class MainActivity2 extends AppCompatActivity {

@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
[Link](this);
setContentView([Link].activity_main2);
[Link](findViewById([Link]), (v, insets) -> {
Insets systemBars = [Link]([Link]());
[Link]([Link], [Link], [Link], [Link]);
return insets;
});

Bundle extras = getIntent().getExtras();


if (extras != null) {
((TextView) findViewById([Link])).setText([Link]("name"));
((TextView) findViewById([Link])).setText([Link]("surname"));
((TextView) findViewById([Link])).setText([Link]("class"));
((TextView) findViewById([Link])).setText([Link]("gender"));
((TextView) findViewById([Link])).setText([Link]("hobbies"));
((TextView) findViewById([Link])).setText([Link]("marks"));
}
}
}

Slip 4. Create an Android Application that sends the Notification on click of the button and
displays the notification message on the second activity.

XML FILE 1
<?xml version="1.0" encoding="utf-8"?>
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/main"
tools:context=".MainActivity">

<Button
android:id="@+id/btnSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send Hello Message"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginTop="200dp"/>
</[Link]>

JAVA FILE 1
package [Link].slip12a;

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

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

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
[Link](this);
setContentView([Link].activity_main);
[Link](findViewById([Link]), (v, insets) -> {
Insets systemBars = [Link]([Link]());
[Link]([Link], [Link], [Link], [Link]);
return insets;
});

Button btnSend = findViewById([Link]);

[Link](new [Link]() {
@Override
public void onClick(View view) {
Intent intent = new Intent([Link], [Link]);
[Link]("message", "Hello!");
startActivity(intent);
}
});
}
}
XML FILE 2
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:gravity="center"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity2">

<TextView
android:id="@+id/tvMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello there"
android:textSize="22sp"
android:textStyle="bold" />

</LinearLayout>

JAVA FILE 2
package [Link].slip12a;

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

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

public class MainActivity2 extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
[Link](this);
setContentView([Link].activity_main2);
[Link](findViewById([Link]), (v, insets) -> {
Insets systemBars = [Link]([Link]());
[Link]([Link], [Link], [Link], [Link]);
return insets;
});

TextView tvMessage = findViewById([Link]);

Intent intent = getIntent();


String message = [Link]("message");
[Link](message);
}
}

Slip 6. Create an Android Application that Demonstrates ListView and Onclick of List Display
the Toast.
Slip 10. Demonstrate Array Adapter using List View to display list of fruits.
Slip 20. Demonstrate Array Adapter using List View to display list of Country.

XML FILE
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:orientation="vertical"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/material_dynamic_primary70"
android:text="Fruits list"
android:textSize="40dp" />
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/list" />

</LinearLayout>

JAVA FILE
package [Link].slip6b1;

import [Link];
import [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 {

@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
[Link](this);
setContentView([Link].activity_main);
[Link](findViewById([Link]), (v, insets) -> {
Insets systemBars = [Link]([Link]());
[Link]([Link], [Link], [Link], [Link]);
return insets;
});

ListView listView;
listView=(ListView) findViewById([Link]);

String[] fruits = {"Apple","Orange","Grape","Papaya","Guava"};


ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>([Link],
[Link].support_simple_spinner_dropdown_item,fruits);
[Link](arrayAdapter);

[Link](new [Link]() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
String str = [Link](i).toString();
[Link]([Link], "Selected "+str, Toast.LENGTH_SHORT).show();
}
});
}
}

Slip 5. Create an Android application that creates a custom Alert Dialog containing Friends
Name and onClick of Friend Name Button greet accordingly.

XML FILE
<?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"
android:padding="20dp">

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

JAVA FILE
package [Link].slip5b1;

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

public class MainActivity extends AppCompatActivity {

private Button btnShowDialog;


private String[] friends = {"Amit", "Priya", "Rahul", "Neha", "Suresh"};

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

btnShowDialog = findViewById([Link]);

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

private void showFriendsDialog() {


[Link] builder = new [Link](this);
[Link]("Select a Friend");

[Link](friends, new [Link]() {


@Override
public void onClick(DialogInterface dialog, int which) {
String selectedFriend = friends[which];
[Link]([Link], "Hello, " + selectedFriend + "!",
Toast.LENGTH_SHORT).show();
}
});

[Link]("Cancel", null);
[Link]().show();
}
}
Slip 8. Create application to send email with attachment.

XML FILE
<?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"
android:padding="20dp">

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

<EditText
android:id="@+id/etSubject"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter subject"/>

<EditText
android:id="@+id/etMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter message"
android:inputType="textMultiLine"/>

<Button
android:id="@+id/btnAttach"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Attach File"/>

<Button
android:id="@+id/btnSend"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Send Email"/>
</LinearLayout>

JAVA FILE
package [Link].slip8b2;

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 EditText etEmail, etSubject, etMessage;


private Button btnAttach, btnSend;
private Uri fileUri;

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

etEmail = findViewById([Link]);
etSubject = findViewById([Link]);
etMessage = findViewById([Link]);
btnAttach = findViewById([Link]);
btnSend = findViewById([Link]);

ActivityResultLauncher<Intent> filePicker = registerForActivityResult(


new [Link](),
result -> {
if ([Link]() == RESULT_OK && [Link]() != null) {
fileUri = [Link]().getData();
[Link]([Link], "File Attached!",
Toast.LENGTH_SHORT).show();
}
});

[Link](v -> {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
[Link]("*/*"); // Allow any file type
[Link](Intent.CATEGORY_OPENABLE);
[Link]([Link](intent, "Select a file"));
});

[Link](v -> sendEmail());


}

private void sendEmail() {


String email = [Link]().toString();
String subject = [Link]().toString();
String message = [Link]().toString();

if ([Link]() || [Link]() || [Link]()) {


[Link](this, "Please fill all fields!", Toast.LENGTH_SHORT).show();
return;
}

Intent emailIntent = new Intent(Intent.ACTION_SEND);


[Link]("message/rfc822");
[Link](Intent.EXTRA_EMAIL, new String[]{email});
[Link](Intent.EXTRA_SUBJECT, subject);
[Link](Intent.EXTRA_TEXT, message);

if (fileUri != null) {
[Link](Intent.EXTRA_STREAM, fileUri);
}

try {
startActivity([Link](emailIntent, "Choose an Email Client"));
} catch (Exception e) {
[Link](this, "No email clients installed!", Toast.LENGTH_SHORT).show();
}
}
}

MANIFEST
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="[Link]
xmlns:tools="[Link]

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

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Slip8b2"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="[Link]" />

<category android:name="[Link]" />


</intent-filter>
</activity>
</application>

</manifest>

Slip 4. Create an android Application for performing the following operation on the table
Customer (id, name, address, phno). (use SQLite database) i) Insert New Customer Details. ii)
Show All the Customer Details on Toast Message.
Slip 9. Create table Company (id, name, address, phno). Create Application for Performing
the following operation on the table. a) Insert New Company details. b) Show All Company
details

XML FILE
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Company Details"
android:textSize="30dp" />

<EditText
android:id="@+id/id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Company ID"
android:textSize="30dp" />

<EditText
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Company Name"
android:textSize="30dp" />

<EditText
android:id="@+id/address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Company Address"
android:textSize="30dp" />

<EditText
android:id="@+id/phno"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Phone No."
android:textSize="30dp" />

<Button
android:id="@+id/addDetails"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="@color/material_dynamic_tertiary10"
android:text="Add Details" />

<Button
android:id="@+id/showDetails"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="@color/material_dynamic_tertiary10"
android:text="Show Details" />

<ListView
android:id="@+id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</LinearLayout>

JAVA FILE
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];

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
[Link](this);
setContentView([Link].activity_main);
[Link](findViewById([Link]), (v, insets) -> {
Insets systemBars = [Link]([Link]());
[Link]([Link], [Link], [Link], [Link]);
return insets;
});

EditText id,name,address,phone;
Button addDetail,showDetail;
ListView listView;
dbHandler dbHandler;

id=(EditText) findViewById([Link]);
name=(EditText) findViewById([Link]);
address=(EditText) findViewById([Link]);
phone=(EditText) findViewById([Link]);
addDetail=(Button) findViewById([Link]);
showDetail=(Button) findViewById([Link]);
listView=(ListView) findViewById([Link]);
dbHandler=new dbHandler([Link]);

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

if ([Link]([Link]().toString())) {
[Link]([Link], "Please Enter the Records",
Toast.LENGTH_SHORT).show();
}
else {

[Link]([Link]().toString(),[Link]().toString(),[Link]
().toString(),[Link]().toString());
[Link]([Link], "Record inserted successfully",
Toast.LENGTH_SHORT).show();
[Link]("");
[Link]("");
[Link]("");
[Link]("");
}
}
});

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

ArrayList<String> arrayList=new ArrayList<>();


ArrayList<companyDetails> companyDetails=[Link]();

for (int i=0;i<[Link]();i++) {


[Link]([Link]([Link](i).id));
[Link]([Link](i).name);
[Link]([Link](i).address);
[Link]([Link]([Link](i).phone));
}

ArrayAdapter<String> arrayAdapter=new ArrayAdapter<String>([Link],


[Link].support_simple_spinner_dropdown_item,arrayList);
[Link](arrayAdapter);
}
});
}
}

[Link]
package [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="companyDB";


private static final int DB_VERSION=1;
private static final String TABLE_NAME="companyDetails";
private static final String ID_COL="id";
private static final String COMPANYNAME_COL="companyName";
private static final String COMPANYADDESS_COL="companyAdd";
private static final String COMPANYPHONE_COL="companyPhone";

public dbHandler(@Nullable Context context) {


super(context, DB_NAME, null, DB_VERSION);
}

@Override
public void onCreate(SQLiteDatabase db) {
String newQuery="CREATE TABLE "+TABLE_NAME+"("+ ID_COL+" INTEGER PRIMARY
KEY,"+COMPANYNAME_COL+" TEXT,"+COMPANYADDESS_COL+"
TEXT,"+COMPANYPHONE_COL+" INTEGER);";
[Link](newQuery);
}

public void addNewCourse(String companyID,String companyName,String


comapnyAddress,String comapnyPhone) {
SQLiteDatabase db=[Link]();
ContentValues values=new ContentValues();

[Link](ID_COL,companyID);
[Link](COMPANYNAME_COL,companyName);
[Link](COMPANYADDESS_COL,comapnyAddress);
[Link](COMPANYPHONE_COL,comapnyPhone);
[Link](TABLE_NAME,null,values);
[Link]();
}

public ArrayList<companyDetails> showDetails() {

ArrayList<companyDetails> companyDetails=new ArrayList<>();


SQLiteDatabase db=getReadableDatabase();
Cursor cursor=[Link]("SELECT * FROM "+TABLE_NAME,null);

while ([Link]()) {
companyDetails company=new companyDetails();
[Link]=[Link](0);
[Link]=[Link](1);
[Link]=[Link](2);
[Link]=[Link](3);
[Link](company);
}
return companyDetails;
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
[Link]("DROP TABLE IF EXISTS "+TABLE_NAME);
onCreate(db);
}
}

(or) Slip 11. Create new contact for designing following layout.

XML FILE
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:orientation="vertical"
android:layout_width="700dp"
android:layout_height="400dp"
tools:context=".MainActivity">

<LinearLayout
android:layout_width="700dp"
android:layout_height="330dp"
android:orientation="horizontal" >

<LinearLayout
android:layout_width="350dp"
android:layout_height="400dp"
android:orientation="vertical" >

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="InsertNewContactUsingIntent"
android:textSize="20dp"
android:background="@color/black"
android:textColor="@color/white"/>

<TextView
android:layout_width="300dp"
android:layout_height="300dp"
android:gravity="center"
android:text="Insert Contact"
android:textSize="30dp" />

</LinearLayout>

<LinearLayout
android:layout_width="350dp"
android:layout_height="400dp"
android:orientation="vertical">

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:background="@drawable/background1"
android:orientation="vertical">

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbarSize="30dp"
android:src="@mipmap/contact1" />

</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbarSize="30dp"
android:background="@drawable/background1"
android:src="@mipmap/call" />

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbarSize="30dp"
android:background="@drawable/background1"
android:src="@mipmap/call1" />

</LinearLayout>

</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@drawable/background1"
android:orientation="vertical">

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Create Contact"
android:textSize="20dp" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Update Existing"
android:textSize="20dp" />

</LinearLayout>

</LinearLayout>

<LinearLayout
android:layout_width="349dp"
android:layout_height="60dp"
android:background="@drawable/background1"
android:orientation="horizontal">

<TextView
android:layout_width="209dp"
android:layout_height="60dp"
android:text="(650)253-000"
android:textColor="@color/material_dynamic_neutral10"
android:textSize="30dp" />

<ImageView
android:layout_width="wrap_content"
android:layout_height="60dp"
android:background="@drawable/background1"
android:src="@mipmap/call3" />

<ImageView
android:layout_width="59dp"
android:layout_height="60dp"
android:background="@drawable/background1"
android:src="@mipmap/call4" />

</LinearLayout>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Record Inserted"
android:textSize="20dp"
android:layout_gravity="center" />

</LinearLayout>

</LinearLayout>

</LinearLayout>

Slip 12. Create a custom "Contact" layout to hold multiple pieces of information, including:
Photo, Name, Contact Number, E-mail id.

XML FILE
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:orientation="vertical"
android:gravity="center"
android:background="@color/material_dynamic_primary90"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Contact Information"
android:textSize="30dp" />

<ImageView
android:layout_width="80sp"
android:layout_height="80sp"
android:id="@+id/image"
android:src="@mipmap/contact_photo" />

<EditText
android:layout_width="151sp"
android:layout_height="wrap_content"
android:hint="Name"
android:textSize="20sp" />

<EditText
android:id="@+id/Phone"
android:layout_width="155sp"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Contact Number"
android:inputType="phone" />

<EditText
android:id="@+id/EmailAddress"
android:layout_width="155sp"
android:layout_height="wrap_content"
android:ems="10"
android:hint="E-mail id"
android:inputType="textEmailAddress" />

</LinearLayout>

Slip 1. Create an Android Application that demonstrate DatePicker and DatePickerDailog.


(or) Slip 12. Create an application to demonstrate date and time picker.
Slip 16. Create an Android Application that Demonstrate TimePicker and display Selected
Time on TextView.

XML FILE
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Date Picker"
android:textSize="30dp"
/>

<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Choose the Date"
android:textSize="30dp"
android:id="@+id/date"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Time Picker"
android:textSize="30dp"
/>

<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Choose the Time"
android:textSize="30dp"
android:id="@+id/time"/>

</LinearLayout>

JAVA FILE
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];

public class MainActivity extends AppCompatActivity {

int year,month,day,hr,min;

@SuppressLint("MissingInflatedId")
@Override

protected void onCreate(Bundle savedInstanceState) {


[Link](savedInstanceState);
[Link](this);
setContentView([Link].activity_main);
[Link](findViewById([Link]), (v, insets) -> {
Insets systemBars = [Link]([Link]());
[Link]([Link], [Link], [Link], [Link]);
return insets;
});

EditText date,time;
date=(EditText) findViewById([Link]);
time=(EditText) findViewById([Link]);

Calendar calendar=[Link]();
[Link](new [Link]() {
@Override
public void onClick(View v) {
year =[Link](([Link]));
month =[Link](([Link]));
day =[Link]((Calendar.DAY_OF_MONTH));

DatePickerDialog datePickerDialog = new DatePickerDialog([Link], new


[Link]() {
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
month=month+1;
[Link](dayOfMonth + "/" + month + "/" + year);
}
},year, month, day);

[Link]();
}
});

[Link](new [Link]() {
@Override
public void onClick(View v) {
hr =[Link](([Link]));
min =[Link](([Link]));

TimePickerDialog timePickerDialog;
timePickerDialog = new TimePickerDialog([Link], new
[Link]() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
[Link](hr +":"+ min);
}
},hr, min,true);

[Link]();
}
});

}
}

Slip 14 Create the following layout which is changing android spinner text size with styles.

XML FILE
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/design_default_color_primary_variant"
android:textColor="@color/white"
android:text="Spinner Style"
android:textSize="40dp"
/>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Coffee?"
android:textSize="35dp"
android:id="@+id/text" />

<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbarSize="100dp"
android:id="@+id/spinner" />

</LinearLayout>

JAVA FILE
package [Link].slip14b1;

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];

public class MainActivity extends AppCompatActivity {

@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
[Link](this);
setContentView([Link].activity_main);
[Link](findViewById([Link]), (v, insets) -> {
Insets systemBars = [Link]([Link]());
[Link]([Link], [Link], [Link], [Link]);
return insets;
});

TextView textView;
Spinner sp;
textView=(TextView) findViewById([Link]);
sp=(Spinner) findViewById([Link]);
String[] list = {"Filter","Americano","Latte","Espresso","Cappucino","Mocha","Skinny
Latte","Espresso Corretto"};

ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>([Link],


[Link].support_simple_spinner_dropdown_item,list);
[Link](arrayAdapter);

[Link](new [Link]() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
String str = [Link](i).toString();
[Link]([Link], "Selected "+str, Toast.LENGTH_SHORT).show();
}

@Override
public void onNothingSelected(AdapterView<?> adapterView) {

}
});
}
}

(or) Slip 14. Create an Android application to send email.

XML FILE
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="@color/material_dynamic_tertiary30"
android:textColor="@color/white"
android:text="Send Email"
android:textSize="50dp" />

<EditText
android:layout_width="match_parent"
android:layout_height="50dp"
android:hint="To: "
android:textSize="20dp"
android:id="@+id/name" />

<EditText
android:layout_width="match_parent"
android:layout_height="80dp"
android:hint="Subject: "
android:textSize="20dp"
android:id="@+id/subject" />

<EditText
android:layout_width="match_parent"
android:layout_height="180dp"
android:hint="Type Content Here: "
android:textSize="20dp"
android:id="@+id/msg" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Send"
android:textSize="30dp"
android:id="@+id/submit" />

</LinearLayout>

JAVA FILE
package [Link];

import [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 {

@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
[Link](this);
setContentView([Link].activity_main);
[Link](findViewById([Link]), (v, insets) -> {
Insets systemBars = [Link]([Link]());
[Link]([Link], [Link], [Link], [Link]);
return insets;
});

EditText name,subject,msg;
Button send;

name=(EditText) findViewById([Link]);
subject=(EditText) findViewById([Link]);
msg=(EditText) findViewById([Link]);
send=(Button) findViewById([Link]);

[Link](new [Link]() {
@Override
public void onClick(View view) {
sendMail();
}
private void sendMail() {
Intent intent=new Intent(Intent.ACTION_SEND.trim());
String[] reci={[Link]().toString().trim()};

[Link](Intent.EXTRA_EMAIL,reci);
[Link](Intent.EXTRA_SUBJECT,[Link]().toString());
[Link](Intent.EXTRA_TEXT,[Link]().toString());

[Link]("message/rfc822");
startActivity([Link](intent,"Choose email"));
}
});

}
}

Slip 15. Create simple application with Login Screen. On successful login, gives message go to
next Activity (Without Using Database).

XML FILE
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:orientation="vertical"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login Form"
android:textSize="40dp" />

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Email ID"
android:id="@+id/email"
android:textSize="30dp" />

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Password"
android:id="@+id/pass"
android:textSize="30dp" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login"
android:id="@+id/button"
android:textSize="30dp" />

</LinearLayout>

JAVA FILE
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];

public class MainActivity extends AppCompatActivity {

@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
[Link](this);
setContentView([Link].activity_main);
[Link](findViewById([Link]), (v, insets) -> {
Insets systemBars = [Link]([Link]());
[Link]([Link], [Link], [Link], [Link]);
return insets;
});
EditText email_id,password;
Button button;

email_id=(EditText) findViewById([Link]);
password=(EditText) findViewById([Link]);

button=(Button) findViewById([Link]);

[Link](new [Link]() {
@Override
public void onClick(View view) {
String input_email=email_id.getText().toString();
String input_pass=[Link]().toString();

if(input_email.isEmpty() && input_pass.isEmpty()) {


[Link]([Link], "Please Enter Fields",
Toast.LENGTH_SHORT).show();
}
else {
if (input_email.equals("admin@[Link]") && input_pass.equals("admin")) {
Intent intent=new Intent([Link],[Link]);
startActivity(intent);
}
else {
[Link]([Link], "Login Failed",
Toast.LENGTH_SHORT).show();
}
}
}
});
}
}

XML FILE 2
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:orientation="vertical"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity2">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="WELCOME TO APPLICATION"
android:textSize="30dp" />

</LinearLayout>

Slip 16. Create a Simple calculator.

XML FILE
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:background="@drawable/calculator"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Simple Calculator!"
android:textSize="40dp"
android:textColor="@color/design_default_color_primary_variant"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<EditText
android:id="@+id/fno"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter First Number" />

<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter Second Number"
android:id="@+id/sno"/>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center" >

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="20dp"
android:text="+"
android:textColorLink="#E91E63" />

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:text="-"
android:textColorLink="#E91E63" />

<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:text="*"
android:textColorLink="#E91E63" />

<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:text="/"
android:textColorLink="#E91E63" />

</LinearLayout>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/output"
android:textSize="40dp"
android:hint="Answer" />

</LinearLayout>

JAVA FILE
package [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 {

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
[Link](this);
setContentView([Link].activity_main);
[Link](findViewById([Link]), (v, insets) -> {
Insets systemBars = [Link]([Link]());
[Link]([Link], [Link], [Link], [Link]);
return insets;
});

TextView t1;
EditText fnum ,snum;
Button b1,b2,b3,b4;

t1=(TextView) findViewById([Link]);
fnum=(EditText) findViewById([Link]);
snum=(EditText) findViewById([Link]);
b1=(Button) findViewById([Link].button1);
b2=(Button) findViewById([Link].button2);
b3=(Button) findViewById([Link].button3);
b4=(Button) findViewById([Link].button4);

[Link](new [Link]() {
@Override
public void onClick(View v) {
int N1,N2,N3;
N1=[Link]([Link]().toString());
N2=[Link]([Link]().toString());
N3=N1+N2;
[Link](" "+N3);
}
});

[Link](new [Link]() {
@Override
public void onClick(View v) {
int N1,N2,N3;
N1=[Link]([Link]().toString());
N2=[Link]([Link]().toString());
N3=N1-N2;
[Link](" "+N3);
}
});

[Link](new [Link]() {
@Override
public void onClick(View v) {
int N1,N2,N3;
N1=[Link]([Link]().toString());
N2=[Link]([Link]().toString());
N3=N1*N2;
[Link](" "+N3);
}
});

[Link](new [Link]() {
@Override
public void onClick(View v) {
int N1,N2,N3;
N1=[Link]([Link]().toString());
N2=[Link]([Link]().toString());
N3=N1/N2;
[Link](" "+N3);
}
});

}
}

Slip 17. Create an Android Application to accept two numbers and find power and Average.
Display the result on the next activity using Context Menu.

XML FILE
<?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"
android:padding="20dp">

<EditText
android:id="@+id/etNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter a number"
android:inputType="number"/>

<TextView
android:id="@+id/tvResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Long Press to Calculate"
android:textSize="18sp"
android:padding="10dp"
android:background="#CCCCCC"
android:gravity="center"/>

</LinearLayout>

JAVA FILE
package [Link].slip17b2;

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

public class MainActivity extends AppCompatActivity {

private EditText etNumber;


private TextView tvResult;

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

etNumber = findViewById([Link]);
tvResult = findViewById([Link]);

registerForContextMenu(tvResult);
}

@Override
public void onCreateContextMenu(ContextMenu menu, View v,
[Link] menuInfo) {
[Link](menu, v, menuInfo);
[Link]("Select Operation");
[Link](0, [Link](), 0, "Calculate Factorial");
[Link](0, [Link](), 0, "Calculate Sum of Digits");
}

@Override
public boolean onContextItemSelected(MenuItem item) {
String numStr = [Link]().toString();

if ([Link]()) {
[Link](this, "Please enter a number!", Toast.LENGTH_SHORT).show();
return false;
}

int num = [Link](numStr);

if ([Link]().equals("Calculate Factorial")) {
long factorial = calculateFactorial(num);
[Link](this, "Factorial: " + factorial, Toast.LENGTH_LONG).show();
} else if ([Link]().equals("Calculate Sum of Digits")) {
int sum = calculateSumOfDigits(num);
[Link](this, "Sum of Digits: " + sum, Toast.LENGTH_LONG).show();
}

return true;
}

private long calculateFactorial(int n) {


if (n == 0 || n == 1) return 1;
long fact = 1;
for (int i = 2; i <= n; i++) {
fact *= i;
}
return fact;
}

private int calculateSumOfDigits(int num) {


int sum = 0;
while (num > 0) {
sum += num % 10;
num /= 10;
}
return sum;
}
}
Slip 18. Create an Android Application to accept two numbers and find power and Average.
Display the result on the next activity using Context Menu.

XML FILE 1
<?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"
android:padding="20dp">

<EditText
android:id="@+id/etNumber1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter First Number"
android:inputType="numberDecimal"/>

<EditText
android:id="@+id/etNumber2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Second Number"
android:inputType="numberDecimal"/>

<TextView
android:id="@+id/tvOptions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Long Press to Calculate"
android:textSize="18sp"
android:padding="10dp"
android:background="#CCCCCC"
android:gravity="center"/>

</LinearLayout>

JAVA FILE 1
package [Link].slip18b2;

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

public class MainActivity extends AppCompatActivity {

private EditText etNumber1, etNumber2;


private TextView tvOptions;

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

etNumber1 = findViewById([Link].etNumber1);
etNumber2 = findViewById([Link].etNumber2);
tvOptions = findViewById([Link]);

registerForContextMenu(tvOptions);
}

@Override
public void onCreateContextMenu(ContextMenu menu, View v,
[Link] menuInfo) {
[Link](menu, v, menuInfo);
[Link]("Select Operation");
[Link](0, [Link](), 0, "Calculate Power");
[Link](0, [Link](), 0, "Calculate Average");
}

@Override
public boolean onContextItemSelected(MenuItem item) {
String num1Str = [Link]().toString();
String num2Str = [Link]().toString();

if ([Link]() || [Link]()) {
[Link](this, "Please enter both numbers!", Toast.LENGTH_SHORT).show();
return false;
}

double num1 = [Link](num1Str);


double num2 = [Link](num2Str);
double result = 0;
String operation = "";

if ([Link]().equals("Calculate Power")) {
result = [Link](num1, num2);
operation = "Power";
} else if ([Link]().equals("Calculate Average")) {
result = (num1 + num2) / 2;
operation = "Average";
}

// Send data to the next Activity


Intent intent = new Intent([Link], [Link]);
[Link]("operation", operation);
[Link]("result", result);
startActivity(intent);

return true;
}
}

XML FILE 2
<?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"
android:padding="20dp">

<TextView
android:id="@+id/tvResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textStyle="bold"/>
</LinearLayout>

JAVA FILE 2
package [Link].slip18b2;

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

public class MainActivity2 extends AppCompatActivity {

private TextView tvResult;

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

tvResult = findViewById([Link]);

String operation = getIntent().getStringExtra("operation");


double result = getIntent().getDoubleExtra("result", 0);

[Link](operation + " Result: " + result);


}
}

Slip 19 . Design Following Screens using Table Layout. Display the entered text on next
activity.

XML FILE 1
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
android:stretchColumns="1">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Membership Form"
android:textSize="22sp"
android:textStyle="bold"
android:gravity="center"
android:layout_span="2"
android:paddingBottom="10dp"/>

<TableRow>
<TextView android:text="Full Name" android:layout_width="wrap_content"/>
<EditText android:id="@+id/etName" android:layout_width="match_parent"/>
</TableRow>

<TableRow>
<TextView android:text="Gender" />
<RadioGroup
android:id="@+id/radioGroupGender"
android:orientation="horizontal">

<RadioButton
android:id="@+id/rbMale"
android:text="Male"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>

<RadioButton
android:id="@+id/rbFemale"
android:text="Female"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>

<RadioButton
android:id="@+id/rbOther"
android:text="Other"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
</RadioGroup>
</TableRow>

<TableRow>
<TextView android:text="Current Weight"/>
<EditText android:id="@+id/etWeight" android:layout_width="match_parent"/>
<TextView android:text="Height"/>
<EditText android:id="@+id/etHeight" android:layout_width="match_parent"/>
</TableRow>

<TableRow>
<TextView android:text="Goal Weight"/>
<EditText android:id="@+id/etGoalWeight" android:layout_width="match_parent"/>

<TextView android:text="Age"/>
<EditText android:id="@+id/etAge" android:layout_width="match_parent"/>
</TableRow>

<TableRow>
<TextView android:text="Phone"/>
<EditText android:id="@+id/etPhone" android:layout_width="match_parent"/>
</TableRow>

<TableRow>
<TextView android:text="Address"/>
<EditText android:id="@+id/etAddress" android:layout_width="match_parent"/>
</TableRow>

<TableRow>
<CheckBox android:id="@+id/checkBox" android:text="I have read, understood, and
accept membership rules"/>
</TableRow>

<TableRow>
<Button android:id="@+id/btnSubmit" android:text="SUBMIT"/>
</TableRow>

</TableLayout>

JAVA FILE 1
package [Link].slip19b1;

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

public class MainActivity extends AppCompatActivity {


EditText etName, etWeight, etHeight, etGoalWeight, etAge, etPhone, etAddress;
RadioGroup radioGroupGender;
CheckBox checkBox;
Button btnSubmit;

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

etName = findViewById([Link]);
etWeight = findViewById([Link]);
etHeight = findViewById([Link]);
etGoalWeight = findViewById([Link]);
etAge = findViewById([Link]);
etPhone = findViewById([Link]);
etAddress = findViewById([Link]);
radioGroupGender = findViewById([Link]);
checkBox = findViewById([Link]);
btnSubmit = findViewById([Link]);

[Link](new [Link]() {
@Override
public void onClick(View v) {
String name = [Link]().toString();
String weight = [Link]().toString();
String height = [Link]().toString();
String goalWeight = [Link]().toString();
String age = [Link]().toString();
String phone = [Link]().toString();
String address = [Link]().toString();

int selectedId = [Link]();


RadioButton selectedRadioButton = findViewById(selectedId);
String gender = (selectedRadioButton != null) ?
[Link]().toString() : "Not Selected";

String membershipAccepted = [Link]() ? "Accepted" : "Not


Accepted";
Intent intent = new Intent([Link], [Link]);
[Link]("name", name);
[Link]("gender", gender);
[Link]("weight", weight);
[Link]("height", height);
[Link]("goalWeight", goalWeight);
[Link]("age", age);
[Link]("phone", phone);
[Link]("address", address);
[Link]("membershipAccepted", membershipAccepted);
startActivity(intent);
}
});
}
}

XML FILE 2
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
android:stretchColumns="1">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submitted Details"
android:textSize="22sp"
android:textStyle="bold"
android:gravity="center"
android:layout_span="2"
android:paddingBottom="10dp"/>

<TableRow>
<TextView
android:text="Full Name"/>
<TextView android:id="@+id/tvName"/>
</TableRow>

<TableRow>
<TextView android:text="Gender"/>
<TextView android:id="@+id/tvGender"/>
</TableRow>

<TableRow>
<TextView android:text="Current Weight"/>
<TextView android:id="@+id/tvWeight"/>
</TableRow>

<TableRow>
<TextView android:text="Height"/>
<TextView android:id="@+id/tvHeight"/>
</TableRow>

<TableRow>
<TextView android:text="Goal Weight"/>
<TextView android:id="@+id/tvGoalWeight"/>
</TableRow>

<TableRow>
<TextView android:text="Age"/>
<TextView android:id="@+id/tvAge"/>
</TableRow>

<TableRow>
<TextView android:text="Phone"/>
<TextView android:id="@+id/tvPhone"/>
</TableRow>

<TableRow>
<TextView android:text="Address"/>
<TextView android:id="@+id/tvAddress"/>
</TableRow>

<TableRow>
<TextView android:text="Membership"/>
<TextView android:id="@+id/tvMembership"/>
</TableRow>

</TableLayout>

JAVA FILE 2
package [Link].slip19b1;

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

public class MainActivity2 extends AppCompatActivity {


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

((TextView) findViewById([Link])).setText(getIntent().getStringExtra("name"));
((TextView)
findViewById([Link])).setText(getIntent().getStringExtra("gender"));
((TextView)
findViewById([Link])).setText(getIntent().getStringExtra("weight"));
((TextView) findViewById([Link])).setText(getIntent().getStringExtra("height"));
((TextView)
findViewById([Link])).setText(getIntent().getStringExtra("goalWeight"));
((TextView) findViewById([Link])).setText(getIntent().getStringExtra("age"));
((TextView) findViewById([Link])).setText(getIntent().getStringExtra("phone"));
((TextView)
findViewById([Link])).setText(getIntent().getStringExtra("address"));
((TextView)
findViewById([Link])).setText(getIntent().getStringExtra("membershipAccept
ed"));
}
}

You might also like