0% found this document useful (0 votes)
9 views69 pages

Android UI Design Assignments

This is Practical assignment of Android development course, this documents includes question and their answers for practice

Uploaded by

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

Android UI Design Assignments

This is Practical assignment of Android development course, this documents includes question and their answers for practice

Uploaded by

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

Name:- Preet Amar Nartekar

Std:- TYBBA(CA).
Div – B
Enroll no:- 2103458
Roll no:- 32177
Subject :- Android Practical Assignment.

Q1. Design login screen using relative layout.


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

<TextView
android:id="@+id/tv1"
android:layout_width="158dp"
android:layout_height="40dp"
android:layout_marginStart="32dp"
android:layout_marginTop="76dp"
android:text="Enter Name "
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
A
<TextView
android:id="@+id/tv2"
android:layout_width="158dp"
android:layout_height="40dp"
android:layout_marginTop="20dp"
android:text="Password"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="@+id/tv1"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/tv1"
app:layout_constraintTop_toBottomOf="@+id/tv1" />

<EditText
android:id="@+id/editusername"
android:layout_width="157dp"
android:layout_height="42dp"
android:layout_marginTop="76dp"
android:ems="10"
android:inputType="text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.468"
app:layout_constraintStart_toEndOf="@+id/tv1"
app:layout_constraintTop_toTopOf="parent" />

<EditText
android:id="@+id/editpassword"
android:layout_width="157dp"
android:layout_height="42dp"
android:layout_marginTop="20dp"
android:ems="10"
android:inputType="text"
app:layout_constraintEnd_toEndOf="@+id/editusername"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/editusername"
app:layout_constraintTop_toBottomOf="@+id/editusername" />

<Button
android:id="@+id/submitbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:layout_marginEnd="124dp"
android:text="Submit"
app:layout_constraintEnd_toEndOf="@+id/editpassword"
app:layout_constraintTop_toBottomOf="@+id/editpassword" />
</[Link]>

[Link]

package [Link].assignmentq1;

import [Link];

import [Link];

public class MainActivity extends AppCompatActivity {

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

Q2. Design screen to send email (compose email) using linear layout.
Ans:-
Activity_main.xml

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


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

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0">

<EditText
android:id="@+id/editTextText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:ems="10"
android:hint="To (Recipient)"
android:inputType="textEmailAddress" />

<EditText
android:id="@+id/editTextText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:ems="10"
android:inputType="text"
android:hint="Subject"/>

<EditText
android:id="@+id/editTextText3"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:ems="10"
android:inputType="textMultiLine"
android:hint="Message"
android:gravity="top"
android:layout_marginBottom="16dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Send Email"></Button>

</LinearLayout>
</[Link]>

[Link]

package [Link].assignmentq2;
import [Link];

import [Link];

public class MainActivity extends AppCompatActivity {

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

OutPut:

Q3. Design screen for calculator using table layout.


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

<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="*"
android:padding="16dp">

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

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_span="4"
android:gravity="end"
android:text="0"
android:textSize="24sp" />

</TableRow>

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

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

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

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

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

</TableRow>

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

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

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

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

<Button
android:id="@+id/button10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="*" />

</TableRow>

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

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

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

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

<Button
android:id="@+id/button15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-" />

</TableRow>

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

<Button
android:id="@+id/button17"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0" />

<Button
android:id="@+id/button18"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="." />

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

<Button
android:id="@+id/button20"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+" />
</TableRow>
</TableLayout>
</[Link]>

[Link]

package [Link].assignmentq3;

import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {

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

Q4. Write a program to check whether a given number is even or odd.


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

<Button
android:id="@+id/checkbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Check"
app:layout_constraintEnd_toEndOf="@+id/enternumber"
app:layout_constraintHorizontal_bias="0.491"
app:layout_constraintStart_toStartOf="@+id/enternumber"
app:layout_constraintTop_toBottomOf="@+id/enternumber" />

<EditText
android:id="@+id/enternumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:ems="10"
android:hint="Enter Number"
android:inputType="text"
app:layout_constraintEnd_toEndOf="@+id/textView2"
app:layout_constraintStart_toStartOf="@+id/textView2"
app:layout_constraintTop_toBottomOf="@+id/textView2" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:text="Check Even Or Odd"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</[Link]>

[Link]

package [Link].assigmentq4;

import [Link];

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

public class MainActivity extends AppCompatActivity {


EditText num;
Button check;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
num = findViewById([Link]);
check = findViewById([Link]);
[Link](new [Link]() {
@Override
public void onClick(View v) {
int n;
n = [Link]([Link]().toString());
if(n%2==0)
{
[Link]([Link], "Even",
Toast.LENGTH_SHORT).show();
}
else
{
[Link]([Link], "Odd",
Toast.LENGTH_SHORT).show();
}
}
});
}
}

OutPut:-

Q5. Write a program for accepting a number using edittext and


calculate factorial on click of button.
Ans:-
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<EditText
android:id="@+id/Enternum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="128dp"
android:layout_marginTop="152dp"
android:layout_marginEnd="73dp"
android:ems="10"
android:hint="Enter Number"
android:inputType="text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/Resulttext"
android:layout_width="58dp"
android:layout_height="wrap_content"
android:layout_marginTop="28dp"
android:text="TextView"
app:layout_constraintEnd_toEndOf="@+id/btnCal"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/btnCal"
app:layout_constraintTop_toBottomOf="@+id/btnCal" />

<Button
android:id="@+id/btnCal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="36dp"
android:text="Calculate"
app:layout_constraintEnd_toEndOf="@+id/Enternum"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/Enternum"
app:layout_constraintTop_toBottomOf="@+id/Enternum" />
</[Link]>

[Link]
package [Link].assignment5;

import [Link];

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

public class MainActivity extends AppCompatActivity {


TextView t1;
Button b1;
EditText ed1;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
t1 = findViewById([Link]);
ed1 = findViewById([Link]);
b1 = findViewById([Link]);
[Link](new [Link]() {
@Override
public void onClick(View v) {
int num , f=1;
num = [Link]([Link]().toString());
for(int i=1; i<=num; i++)
{
f= f*i;
}
[Link]("Factorial = "+f);
}
});
}
}

Ouput
Q6. Write a program to accept a string from the user and convert to
uppercase and vice versa.
Ans:-
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:id="@+id/Result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="192dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="161dp"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btnlower" />

<Button
android:id="@+id/btnupper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="Upper"
app:layout_constraintStart_toStartOf="@+id/enterstring"
app:layout_constraintTop_toBottomOf="@+id/enterstring" />

<Button
android:id="@+id/btnlower"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="Lower"
app:layout_constraintEnd_toEndOf="@+id/enterstring"
app:layout_constraintTop_toBottomOf="@+id/enterstring" />

<EditText
android:id="@+id/enterstring"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="99dp"
android:ems="10"
android:hint="Enter String"
android:inputType="text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</[Link]>

[Link]
package [Link].assigmentq6;

import [Link];

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

public class MainActivity extends AppCompatActivity {

EditText txt;
Button btnup,btnlow;
TextView result ;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

txt = findViewById([Link]);
btnup =findViewById([Link]);
btnlow = findViewById([Link]);
result = findViewById([Link]);

[Link](new [Link]() {
@Override
public void onClick(View v) {
String str;
str = [Link]().toString();
[Link]([Link]());
}
});
[Link](new [Link]() {
@Override
public void onClick(View v) {
String str;
str = [Link]().toString();
[Link]([Link]());
}
});
}
}

Output:-
Q7. Create a Simple Application Which Shows Life Cycle of Activity.
Ans:-
Acitivity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="147dp"
android:text="This is Activity 1"
android:textSize="34sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/btnclick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="44dp"
android:text="Click Here"
app:layout_constraintEnd_toEndOf="@+id/textView"
app:layout_constraintHorizontal_bias="0.496"
app:layout_constraintStart_toStartOf="@+id/textView"
app:layout_constraintTop_toBottomOf="@+id/textView" />
</[Link]>

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

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="207dp"
android:text="Hello This Is Activity 2 "
android:textSize="34sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</[Link]>

[Link]:
package [Link].assignmentq7;

import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
Button bt1 ;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
bt1 = findViewById([Link]);
[Link](new [Link]() {
@Override
public void onClick(View v) {
Intent int1 = new Intent(getApplicationContext(),
[Link]);
startActivity(int1);
}
});
}
}

Output:-
Q8. Create a Simple Application Which Send ―Hello‖ message from
one activity to another with help of Button (Use Intent).
Ans:-
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<EditText
android:id="@+id/entermsg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:ems="10"
android:hint="Enter Message"
android:inputType="text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/sendbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="46dp"
android:text="Send"
app:layout_constraintEnd_toEndOf="@+id/entermsg"
app:layout_constraintStart_toStartOf="@+id/entermsg"
app:layout_constraintTop_toBottomOf="@+id/entermsg" />
</[Link]>

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

<TextView
android:id="@+id/Result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="200dp"
android:text="TextView"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.171"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</[Link]>

[Link]
package [Link].assignmentq8;

import [Link];

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

public class MainActivity extends AppCompatActivity {


EditText ed1;
Button b1;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
ed1 = findViewById([Link]);
b1 = findViewById([Link]);
[Link](new [Link]() {
@Override
public void onClick(View v) {
String str = [Link]().toString();
Intent myint = new Intent(getApplicationContext(),
[Link]);
[Link]("msg", str);
startActivity(myint);
}
});
}
}

[Link]
package [Link].assignmentq8;

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

public class Resultpage extends AppCompatActivity {


TextView t1;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_resultpage);
t1 = findViewById([Link]);
Bundle bd2 = getIntent().getExtras();
if (bd2 != null) {
String str = [Link]("msg");
if (str != null) {
[Link]("Your Message " + str);
} else {
[Link]("No message received");
}
}
}
}

Output:-
Q9. Create simple application with Login Screen. On successful
login, gives message go to next Activity (Without Using Database).
Ans:-
[Link]
<?xml version="1.0" encoding="utf-8"?>
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<EditText
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:ems="10"
android:hint="Password"
android:inputType="text"
android:textSize="28sp"
app:layout_constraintEnd_toEndOf="@+id/username"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/username"
app:layout_constraintTop_toBottomOf="@+id/username" />

<Button
android:id="@+id/loginbtn"
android:layout_width="153dp"
android:layout_height="56dp"
android:layout_marginTop="56dp"
android:layout_marginEnd="88dp"
android:text="Login"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="@+id/password"
app:layout_constraintTop_toBottomOf="@+id/password" />

<EditText
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:ems="10"
android:hint="Username"
android:inputType="text"
android:textSize="28sp"
app:layout_constraintEnd_toEndOf="@+id/textView"
app:layout_constraintStart_toStartOf="@+id/textView"
app:layout_constraintTop_toBottomOf="@+id/textView" />

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="104dp"
android:text="Login Page"
android:textSize="34sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</[Link]>

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

<TextView
android:id="@+id/textView2"
android:layout_width="229dp"
android:layout_height="55dp"
android:text="Welcome"
android:textSize="34sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.554"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.318" />
</[Link]>

[Link]

package [Link].assignmentq9;

import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
private static final String Correct_Username = "user";
private static final String Correct_Password = "pass";
EditText ed1user, ed2pass;
Button b1;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
ed1user = findViewById([Link]);
ed2pass =findViewById([Link]);
b1 = findViewById([Link]);
[Link](new [Link]() {
@Override
public void onClick(View v) {
String username = [Link]().toString();
String password = [Link]().toString();

if([Link](Correct_Username)&&[Link](Correct_Password))
{
[Link]([Link], "Login Successfully",
Toast.LENGTH_LONG).show();
Intent intent = new Intent([Link],
[Link]);
startActivity(intent);
}
else {
[Link]([Link], "Invalid Password",
Toast.LENGTH_LONG).show();
}
}
});
}
}

[Link]
package [Link].assignmentq9;

import [Link];

import [Link];

public class LoginActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_login);
}
}
Output:-
Q10. Create First Activity to accept information like Student First
Name, Middle Name, LastName, Date of birth, Address, Email ID
and display all information on Second Activity when user click on
Submit button.
Ans:- [Link]
<?xml version="1.0" encoding="utf-8"?>
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<EditText
android:id="@+id/fname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="51dp"
android:ems="10"
android:hint="First Name"
android:inputType="text"
android:textSize="26sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<EditText
android:id="@+id/mname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:ems="10"
android:hint="Middle Name"
android:inputType="text"
android:textSize="26sp"
app:layout_constraintEnd_toEndOf="@+id/fname"
app:layout_constraintStart_toStartOf="@+id/fname"
app:layout_constraintTop_toBottomOf="@+id/fname" />

<EditText
android:id="@+id/lname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:ems="10"
android:hint="Last Name"
android:inputType="text"
android:textSize="26sp"
app:layout_constraintEnd_toEndOf="@+id/mname"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/mname"
app:layout_constraintTop_toBottomOf="@+id/mname" />

<EditText
android:id="@+id/dob"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:ems="10"
android:hint="Date of Birth"
android:inputType="text"
android:textSize="26sp"
app:layout_constraintEnd_toEndOf="@+id/lname"
app:layout_constraintStart_toStartOf="@+id/lname"
app:layout_constraintTop_toBottomOf="@+id/lname" />

<EditText
android:id="@+id/Email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:ems="10"
android:hint="Email ID"
android:inputType="text"
android:textSize="26sp"
app:layout_constraintEnd_toEndOf="@+id/dob"
app:layout_constraintStart_toStartOf="@+id/dob"
app:layout_constraintTop_toBottomOf="@+id/dob" />

<EditText
android:id="@+id/address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:ems="10"
android:hint="Address"
android:inputType="text"
android:textSize="26sp"
app:layout_constraintEnd_toEndOf="@+id/Email"
app:layout_constraintStart_toStartOf="@+id/Email"
app:layout_constraintTop_toBottomOf="@+id/Email" />

<Button
android:id="@+id/Submitbtn"
android:layout_width="145dp"
android:layout_height="53dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="80dp"
android:text="Submit"
app:layout_constraintEnd_toEndOf="@+id/address"
app:layout_constraintTop_toBottomOf="@+id/address" />
</[Link]>

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

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.255"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.116" />
</[Link]>

[Link]
package [Link].assignmentq10;
import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
EditText ed1, ed2, ed3, ed4,ed5, ed6;
Button b1;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
ed1 = findViewById([Link]);
ed2 = findViewById([Link]);
ed3 = findViewById([Link]);
ed4 = findViewById([Link]);
ed5 = findViewById([Link]);
ed6 = findViewById([Link]);
b1 = findViewById([Link]);
[Link](new [Link]() {
@Override
public void onClick(View v) {
String fname, mname, lname, dob, email, address;

fname = [Link]().toString();
mname = [Link]().toString();
lname = [Link]().toString();
dob = [Link]().toString();
email = [Link]().toString();
address = [Link]().toString();

Intent intent = new Intent([Link],


[Link]);
Bundle bd1 = new Bundle();
[Link]("1",fname);
[Link]("2",mname);
[Link]("3",lname);
[Link]("4",dob);
[Link]("5",email);
[Link]("6",address);
[Link](bd1);
startActivity(intent);
}
});
}
}

[Link]
package [Link].assignmentq10;

import [Link];

import [Link];
import [Link];

public class OutputActivity extends AppCompatActivity {


TextView t1;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_output);
t1 = findViewById([Link]);
Bundle bd2 = getIntent().getExtras();
[Link]("First Name "+[Link]("1")+"\n"+
"Middle Name "+[Link]("2")+"\n"+
"Last Name"+[Link]("3")+ "\n"+
"Date of birth "+[Link]("4")+"\n"+
"Email Id "+[Link]("5")+"\n"+
"Address"+[Link]("6"));

}
}

Output:-
Q11. Design Following Screens Using Intents. On second activity
take Button. On clicking it, it should Show Information of profile on
Third activity. (Without Using Database).
Ans:-
[Link]
<?xml version="1.0" encoding="utf-8"?>
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".InfoActivity">

<EditText
android:id="@+id/adharNo"
android:layout_width="251dp"
android:layout_height="50dp"
android:layout_marginTop="92dp"
android:ems="10"
android:hint="Aadhar no:"
android:inputType="text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<EditText
android:id="@+id/userName"
android:layout_width="251dp"
android:layout_height="50dp"
android:layout_marginTop="16dp"
android:ems="10"
android:hint="Name"
android:inputType="text"
app:layout_constraintEnd_toEndOf="@+id/adharNo"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/adharNo"
app:layout_constraintTop_toBottomOf="@+id/adharNo" />

<EditText
android:id="@+id/Dateofbirth"
android:layout_width="251dp"
android:layout_height="50dp"
android:ems="10"
android:inputType="text"
android:hint="Date of Birth"
app:layout_constraintEnd_toEndOf="@+id/userName"
app:layout_constraintStart_toStartOf="@+id/userName"
app:layout_constraintTop_toBottomOf="@+id/userName" />

<EditText
android:id="@+id/Gender"
android:layout_width="251dp"
android:layout_height="50dp"
android:layout_marginTop="12dp"
android:ems="10"
android:inputType="text"
android:hint="Gender"
app:layout_constraintEnd_toEndOf="@+id/Dateofbirth"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/Dateofbirth"
app:layout_constraintTop_toBottomOf="@+id/Dateofbirth" />

<EditText
android:id="@+id/Address"
android:layout_width="251dp"
android:layout_height="50dp"
android:layout_marginTop="24dp"
android:ems="10"
android:hint="Address"
android:inputType="text"
app:layout_constraintEnd_toEndOf="@+id/Gender"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/Gender"
app:layout_constraintTop_toBottomOf="@+id/Gender" />

<EditText
android:id="@+id/contact"
android:layout_width="251dp"
android:layout_height="50dp"
android:layout_marginTop="24dp"
android:ems="10"
android:inputType="text"
android:hint="Contact"
app:layout_constraintEnd_toEndOf="@+id/Address"
app:layout_constraintStart_toStartOf="@+id/Address"
app:layout_constraintTop_toBottomOf="@+id/Address" />

<Button
android:id="@+id/Submitbtn"
android:layout_width="132dp"
android:layout_height="54dp"
android:layout_marginTop="56dp"
android:layout_marginEnd="60dp"
android:text="Submit"
app:layout_constraintEnd_toEndOf="@+id/contact"
app:layout_constraintTop_toBottomOf="@+id/contact" />

</[Link]>

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

<TextView
android:id="@+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="125dp"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</[Link]>

[Link]
package [Link].assignmentq11;
import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class InfoActivity extends AppCompatActivity {
EditText ed1,ed2,ed3, ed4, ed5, ed6;
Button b1;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_info);
ed1 = findViewById([Link]);
ed2 = findViewById([Link]);
ed3 = findViewById([Link]);
ed4 = findViewById([Link]);
ed5 = findViewById([Link]);
ed6 = findViewById([Link]);
b1 = findViewById([Link]);
[Link](new [Link]() {
@Override
public void onClick(View v) {
String adno = [Link]().toString();
String user = [Link]().toString();
String dateofbirth = [Link]().toString();
String Gender = [Link]().toString();
String address = [Link]().toString();
String contact = [Link]().toString();

Bundle bd1 = new Bundle();


[Link]("1",adno);
[Link]("2",user);
[Link]("3",dateofbirth);
[Link]("4",Gender);
[Link]("5",address);
[Link]("6",contact);
Intent intent = new
Intent(getApplicationContext(),[Link]);
[Link](bd1);
startActivity(intent);
}
});
}
}

[Link]
package [Link].assignmentq11;
import [Link];

import [Link];
import [Link];
public class Result extends AppCompatActivity {
TextView t1;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_result);
Bundle bundle = getIntent().getExtras();
String adno = [Link]("1");
String user = [Link]("2");
String dateofbirth = [Link]("3");
String gender = [Link]("4");
String address = [Link]("5");
String contact = [Link]("6");
TextView tv1 = findViewById([Link].tv1);
[Link]("Adhar No: " + adno + "\n" +
"User: " + user + "\n" +
"Date of Birth: " + dateofbirth + "\n" +
"Gender: " + gender + "\n" +
"Address: " + address + "\n" +
"Contact: " + contact);
}
}

Output
[Link] Following Screens Using Radio/buttons & CheckBoxes.
Display the selected text using Toast.

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

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:text="Radio Button and Checkbox Demo"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.17"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<RadioGroup
android:id="@+id/rg1"
android:layout_width="367dp"
android:layout_height="159dp"
android:layout_marginTop="16dp"
app:layout_constraintEnd_toEndOf="@+id/textView"
app:layout_constraintHorizontal_bias="0.126"
app:layout_constraintStart_toStartOf="@+id/textView"
app:layout_constraintTop_toBottomOf="@+id/textView">

<RadioButton
android:id="@+id/fybba"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="FYBBA CA" />

<RadioButton
android:id="@+id/sybba"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SYBBA CA" />

<RadioButton
android:id="@+id/tybba"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TYBBA CA" />
</RadioGroup>

<CheckBox
android:id="@+id/cpp"
android:layout_width="200dp"
android:layout_height="35dp"
android:layout_marginTop="20dp"
android:text="C++"
app:layout_constraintEnd_toEndOf="@+id/rg1"
app:layout_constraintHorizontal_bias="0.508"
app:layout_constraintStart_toStartOf="@+id/rg1"
app:layout_constraintTop_toBottomOf="@+id/rg1" />

<CheckBox
android:id="@+id/ds"
android:layout_width="200dp"
android:layout_height="35dp"
android:layout_marginTop="24dp"
android:text="DS USING C"
app:layout_constraintEnd_toEndOf="@+id/cpp"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/cpp"
app:layout_constraintTop_toBottomOf="@+id/cpp" />

<CheckBox
android:id="@+id/csharp"
android:layout_width="200dp"
android:layout_height="35dp"
android:layout_marginTop="28dp"
android:text="C#"
app:layout_constraintEnd_toEndOf="@+id/ds"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/ds"
app:layout_constraintTop_toBottomOf="@+id/ds" />

<CheckBox
android:id="@+id/java"
android:layout_width="200dp"
android:layout_height="35dp"
android:layout_marginTop="36dp"
android:text="JAVA"
app:layout_constraintEnd_toEndOf="@+id/csharp"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/csharp"
app:layout_constraintTop_toBottomOf="@+id/csharp" />
<Button
android:id="@+id/displaybtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="80dp"
android:layout_marginTop="40dp"
android:text="Display"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/java" />

<Button
android:id="@+id/clearbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:layout_marginEnd="80dp"
android:text="Clear"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/java" />

</[Link]>

[Link]
package [Link].assignq12;
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);
setContentView([Link].activity_main);
RadioGroup radioGroup = findViewById([Link].rg1);
CheckBox cppCheckBox = findViewById([Link]);
CheckBox dsCheckBox = findViewById([Link]);
CheckBox csharpCheckBox = findViewById([Link]);
CheckBox javaCheckBox = findViewById([Link]);

Button displayBtn = findViewById([Link]);


Button clearBtn = findViewById([Link]);

[Link](new [Link]() {
@Override
public void onClick(View view) {
displaySelectedOptions(radioGroup, cppCheckBox, dsCheckBox,
csharpCheckBox, javaCheckBox);
}
});

[Link](new [Link]() {
@Override
public void onClick(View view) {
clearSelections(radioGroup, cppCheckBox, dsCheckBox,
csharpCheckBox, javaCheckBox);
}
});
}
private void displaySelectedOptions(
RadioGroup radioGroup,
CheckBox cppCheckBox,
CheckBox dsCheckBox,
CheckBox csharpCheckBox,
CheckBox javaCheckBox)
{

int selectedRadioId = [Link]();


RadioButton selectedRadio = findViewById(selectedRadioId);

String radioText = (selectedRadio != null) ?


[Link]().toString() : "No radio selection";
String cppText = [Link]() ?
[Link]().toString() : "";
String dsText = [Link]() ?
[Link]().toString() : "";
String csharpText = [Link]() ?
[Link]().toString() : "";
String javaText = [Link]() ?
[Link]().toString() : "";

String selectedText = "Radio: " + radioText + "\nC++: " + cppText +


"\nDS: " + dsText + "\nC#: " + csharpText + "\nJava: " + javaText;
showToast(selectedText);
}

private void clearSelections(


RadioGroup radioGroup,
CheckBox cppCheckBox,
CheckBox dsCheckBox,
CheckBox csharpCheckBox,
CheckBox javaCheckBox) {

[Link]();
[Link](false);
[Link](false);
[Link](false);
[Link](false);
}
private void showToast(String message) {
[Link](this, message, Toast.LENGTH_LONG).show();
}

}
Output:-

13.)Design Following Screens using Table Layout. Display the


entered text using Toast.
Ans:-
[Link]
<?xml version="1.0" encoding="utf-8"?>
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TableLayout
android:layout_width="409dp"
android:layout_height="729dp"
tools:layout_editor_absoluteX="1dp"
tools:layout_editor_absoluteY="1dp">

<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="2">

<TextView
android:id="@+id/firstname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="First Name"
android:textSize="20sp"
android:textStyle="bold" />

<EditText
android:id="@+id/editfname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
/>
</TableRow>

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

<TextView
android:id="@+id/lastname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Last Name"
android:textSize="20sp"
android:textStyle="bold"/>

<EditText
android:id="@+id/editlastname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
/>

</TableRow>

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

<TextView
android:id="@+id/address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Address"
android:textSize="20sp"
android:textStyle="bold"/>

<EditText
android:id="@+id/editaddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
/>

</TableRow>

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

<TextView
android:id="@+id/phone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Phone No:- "
android:textSize="20sp"
android:textStyle="bold"/>

<EditText
android:id="@+id/editphone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
/>
</TableRow>

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

<TextView
android:id="@+id/email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email Id :-"
android:textSize="20sp"
android:textStyle="bold"/>

<EditText
android:id="@+id/editemail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
/>

</TableRow>

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

<RadioButton
android:id="@+id/r1male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male"
android:textSize="20sp"
android:textStyle="bold"/>
</TableRow>

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

<RadioButton
android:id="@+id/r2female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female"
android:textSize="20sp"
android:textStyle="bold"/>
</TableRow>

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

<Button
android:id="@+id/b1submit"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Submit"
android:textSize="20sp"
android:textStyle="bold" />

<Button
android:id="@+id/b2clear"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Clear"
android:textSize="20sp"
android:textStyle="bold"
android:layout_weight="1"/>
</TableRow>

<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="@+id/Results"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Result"
android:textSize="20sp"
android:textStyle="bold"/>
</TableRow>

</TableLayout>
</[Link]>

[Link]
package [Link];

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

import [Link];

public class MainActivity extends AppCompatActivity {

private EditText editFirstName, editLastName, editAddress, editPhone,


editEmail;
private RadioButton radioMale, radioFemale;
private Button submitButton, clearButton;
private TextView textViewDetails;

@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
// Initialize your views
editFirstName = findViewById([Link]);
editLastName = findViewById([Link]);
editAddress = findViewById([Link]);
editPhone = findViewById([Link]);
editEmail = findViewById([Link]);
radioMale = findViewById([Link].r1male);
radioFemale = findViewById([Link].r2female);
submitButton = findViewById([Link].b1submit);
clearButton = findViewById([Link].b2clear);
textViewDetails = findViewById([Link]);
//textViewDetails = findViewById([Link]); // assuming
you have a TextView with this ID

// Set click listener for the submit button


[Link](new [Link]() {
@Override
public void onClick(View view) {
// Get user input
String firstName = [Link]().toString();
String lastName = [Link]().toString();
String address = [Link]().toString();
String phone = [Link]().toString();
String email = [Link]().toString();
String gender = [Link]() ? "Male" :
([Link]() ? "Female" : "Not specified");

// Create a string with the user details


String userDetails = "First Name: " + firstName + "\n" +
"Last Name: " + lastName + "\n" +
"Address: " + address + "\n" +
"Phone: " + phone + "\n" +
"Email: " + email + "\n" +
"Gender: " + gender;

// Display the details in the TextView


[Link](userDetails);
}
});

// Set click listener for the clear button


[Link](new [Link]() {
@Override
public void onClick(View view) {
// Clear all EditText fields
[Link]().clear();
[Link]().clear();
[Link]().clear();
[Link]().clear();
[Link]().clear();

// Clear RadioButton selection


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

// Clear the TextView


[Link]("");
}
});
}
}
Output:-

14. Create application to demonstrate date and time picker.


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

<EditText
android:id="@+id/editTextText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="64dp"
android:ems="10"
android:hint="Choose Date"
android:inputType="text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.278"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</[Link]>
[Link]
package [Link].assignmentq14;
import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
EditText ed1;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
ed1 = findViewById([Link]);
[Link](new [Link]() {
@Override
public void onClick(View v) {
DatePickerDialog dtp = new
DatePickerDialog([Link], AlertDialog.THEME_HOLO_DARK);
[Link](new
[Link]() {
@Override
public void onDateSet(DatePicker view, int year, int
month, int dayOfMonth) {
[Link](dayOfMonth+"/"+(year+1)+"/"+month);
}
});
[Link]();
}
});
}
}

Output:-
15. Create an application to demonstrate list view using adapters.
Ans:-
[Link]
<?xml version="1.0" encoding="utf-8"?>
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<ListView
android:id="@+id/list1"
android:layout_width="409dp"
android:layout_height="729dp"
android:layout_marginStart="1dp"
android:layout_marginTop="1dp"
android:layout_marginEnd="1dp"
android:layout_marginBottom="1dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</[Link]>
[Link]
package [Link].assignmentq15;

import [Link];

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

import [Link];

public class MainActivity extends AppCompatActivity {


ListView l1, l2;
String ist1[] = {"item1","item2","item3"};
ArrayList<String> it = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
l1 = findViewById([Link].list1);
ArrayAdapter adapter = new ArrayAdapter(this,
[Link].simple_expandable_list_item_1,ist1);
ArrayAdapter adapter1 = new ArrayAdapter(this,
[Link].simple_expandable_list_item_1);

[Link](adapter);
[Link](new [Link]() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int
position, long id) {
[Link]([Link](position).toString());
}

});

}
}
Output:-

16. Create the following layout using spinner.

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

<Spinner
android:id="@+id/spinner1"
android:layout_width="409dp"
android:layout_height="57dp"
android:layout_marginStart="1dp"
android:layout_marginTop="146dp"
android:layout_marginEnd="1dp"
android:layout_marginBottom="561dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</[Link]>

[Link]
package [Link].assignmentq16;

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

public class MainActivity extends AppCompatActivity {

Spinner spBank;
String[] bank = {"BOI", "SBI", "HDFC", "PNB", "OBC"};
String bk;

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

spBank = findViewById([Link].spinner1);
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
[Link].simple_expandable_list_item_1, bank);
[Link](adapter);

[Link](new
[Link]() {
@Override
public void onItemSelected(AdapterView<?> parentView, View
selectedItemView, int position, long id) {
bk = bank[position];
}

@Override
public void onNothingSelected(AdapterView<?> parentView) {
// Do nothing here if you don't need to handle this case
}
});
}
}
Output:-

17. Create an Android App that creates a file [Link] in Internal


Storage. On click of Read button display the data in textView.
Ans:-
[Link]
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
tools:context=".MainActivity">

<Button
android:id="@+id/writeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="16dp"
android:onClick="writeToFile"
android:text="Write to File" />
<Button
android:id="@+id/readButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Read from File"
android:layout_below="@+id/writeButton"
android:layout_centerHorizontal="true"
android:onClick="readFromFile"/>

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/readButton"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"/>
</RelativeLayout>

[Link]
package [Link].assignmentq17;
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 {
private static final String FILE_NAME = "[Link]";
private Button writeButton, readButton;
private TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
writeButton = findViewById([Link]);
readButton = findViewById([Link]);
textView = findViewById([Link]);
}
public void writeToFile(View view) {
String content = "Hello, this is the content of the file.";
try (FileOutputStream fos = openFileOutput(FILE_NAME,
Context.MODE_PRIVATE)) {
[Link]([Link]());
[Link]("File written successfully.");
} catch (IOException e) {
[Link]();
[Link]("Error writing to file.");
}
}

public void readFromFile(View view) {


try (FileInputStream fis = openFileInput(FILE_NAME);
BufferedReader reader = new BufferedReader(new
InputStreamReader(fis))) {
StringBuilder content = new StringBuilder();
String line;
while ((line = [Link]()) != null) {
[Link](line).append("\n");
}
[Link]("File content:\n" + [Link]());
} catch (IOException e) {
[Link]();
[Link]("Error reading from file.");
}
}
}

Output:-
18. Create an Android App that creates a file [Link] in Internal
Storage. On click of Reverse button display the content of [Link] in
reverse order.
Ans:-
[Link]
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
tools:context=".MainActivity">

<Button
android:id="@+id/writeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Write to File"
android:layout_centerHorizontal="true"
android:layout_marginBottom="16dp"
android:onClick="writeToFile"/>

<Button
android:id="@+id/reverseButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reverse"
android:layout_below="@+id/writeButton"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:onClick="reverseFileContent"/>

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/reverseButton"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"/>
</RelativeLayout>

[Link]
package [Link].assignmentq18;

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 {

private static final String FILE_NAME = "[Link]";


private Button writeButton, reverseButton;
private TextView textView;

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

writeButton = findViewById([Link]);
reverseButton = findViewById([Link]);
textView = findViewById([Link]);
}

public void writeToFile(View view) {


String content = "Hello, this is the content of the file.";

try (FileOutputStream fos = openFileOutput(FILE_NAME,


Context.MODE_APPEND)) {
content += "\n"; // Add a newline before appending
[Link]([Link]());
[Link]("File written successfully.");
} catch (IOException e) {
[Link]();
[Link]("Error writing to file.");
}
}

public void reverseFileContent(View view) {


try (FileInputStream fis = openFileInput(FILE_NAME);
BufferedReader reader = new BufferedReader(new
InputStreamReader(fis))) {

StringBuilder reversedContent = new StringBuilder();


String line;

while ((line = [Link]()) != null) {


StringBuilder reversedLine = new
StringBuilder(line).reverse();
[Link](reversedLine).append("\n");
}

[Link]("Reversed file content:\n" +


[Link]());
} catch (IOException e) {
[Link]();
[Link]("Error reading from file.");
}
}

Output
19. Create an application with a login module (Check username and
password). On successful login, pass username to next screen And on
failing login, alert user using Toast (Hint :UseLogin(username,
password) Table.).
Ans:-
[Link]

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


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

<EditText
android:id="@+id/editTextUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username"/>

<EditText
android:id="@+id/editTextPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/editTextUsername"
android:layout_marginTop="8dp"
android:inputType="textPassword"
android:hint="Password"/>

<Button
android:id="@+id/loginButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:layout_below="@+id/editTextPassword"
android:layout_marginTop="16dp"
android:onClick="login"/>

</RelativeLayout>
[Link]
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
tools:context=".secondactivity">

<TextView
android:id="@+id/textViewUsername"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome, "
android:textSize="18sp"
android:layout_centerInParent="true"/>
</RelativeLayout>

[Link]
package [Link].assignmentq19;

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

import [Link];

public class DatabaseHelper extends SQLiteOpenHelper {

private static final String DATABASE_NAME = "login_database";


private static final int DATABASE_VERSION = 1;
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, 1);
}

@Override
public void onCreate(SQLiteDatabase db) {
[Link]("CREATE TABLE Login (Username TEXT PRIMARY KEY, Password
TEXT)");

// Insert a sample user for testing


[Link]("INSERT INTO Login (Username, Password) VALUES
('testuser', 'testpassword')");

}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int
newVersion) {

}
public boolean checkLogin(String username, String password) {
SQLiteDatabase db = [Link]();
String query = "SELECT * FROM Login WHERE Username=? AND
Password=?";
Log.d("LoginCheck", "Query: " + query);
Cursor cursor = [Link](query, new String[]{username,
password});
boolean isValid = [Link]() > 0;
Log.d("LoginCheck", "isValid: " + isValid);
[Link]();
[Link]();
return isValid;
}
}

[Link]
package [Link].assignmentq19;

import [Link];

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

public class MainActivity extends AppCompatActivity {

EditText editTextUsername, editTextPassword;


DatabaseHelper databaseHelper;

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

editTextUsername = findViewById([Link]);
editTextPassword = findViewById([Link]);

databaseHelper = new DatabaseHelper(this);


}
public void login(View view) {
String username = [Link]().toString().trim();
String password = [Link]().toString().trim();

if ([Link](username, password)) {
// Successful login
Intent intent = new Intent(this, [Link]);
[Link]("USERNAME", username);
startActivity(intent);
} else {
// Failed login
[Link](this, "Invalid username or password",
Toast.LENGTH_SHORT).show();
}
}

}
[Link]
package [Link].assignmentq19;

import [Link];

import [Link];
import [Link];

public class secondactivity extends AppCompatActivity {

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

TextView textViewUsername = findViewById([Link]);

String username = getIntent().getStringExtra("USERNAME");

[Link]("Welcome, " + username + "!");

}
}

Output:
20. Create an application to insert student information(Roll, Name,
email,contact no, gender,class) to the database.

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

<EditText
android:id="@+id/editTextRoll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Roll"/>

<EditText
android:id="@+id/editTextName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/editTextRoll"
android:layout_marginTop="8dp"
android:hint="Name"/>

<EditText
android:id="@+id/editTextEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/editTextName"
android:layout_marginTop="8dp"
android:inputType="textEmailAddress"
android:hint="Email"/>

<EditText
android:id="@+id/editTextContactNo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/editTextEmail"
android:layout_marginTop="8dp"
android:inputType="phone"
android:hint="Contact No"/>

<RadioGroup
android:id="@+id/radioGroupGender"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/editTextContactNo"
android:layout_marginTop="8dp"
android:orientation="horizontal">

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

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

<EditText
android:id="@+id/editTextClass"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/radioGroupGender"
android:layout_marginTop="8dp"
android:hint="Class"/>

<Button
android:id="@+id/buttonInsert"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Insert"
android:layout_below="@+id/editTextClass"
android:layout_marginTop="16dp"
android:onClick="insertStudent"/>

</RelativeLayout>

[Link]
package [Link].assignmentq20;

import [Link];

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

public class MainActivity extends AppCompatActivity {

EditText editTextRoll, editTextName, editTextEmail, editTextContactNo,


editTextClass;
RadioGroup radioGroupGender;
DatabaseHelper databaseHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
editTextRoll = findViewById([Link]);
editTextName = findViewById([Link]);
editTextEmail = findViewById([Link]);
editTextContactNo = findViewById([Link]);
editTextClass = findViewById([Link]);
radioGroupGender = findViewById([Link]);
databaseHelper = new DatabaseHelper(this);

}
public void insertStudent(View view) {
int roll =
[Link]([Link]().toString().trim());
String name = [Link]().toString().trim();
String email = [Link]().toString().trim();
String contactNo = [Link]().toString().trim();
String className = [Link]().toString().trim();

RadioButton selectedGenderRadioButton =
findViewById([Link]());
String gender = [Link]().toString();

long result = [Link](roll, name, email,


contactNo, gender, className);

if (result != -1) {
// Student inserted successfully
[Link](this, "Student information inserted
successfully", Toast.LENGTH_SHORT).show();
} else {
// Error inserting student
[Link](this, "Error inserting student information",
Toast.LENGTH_SHORT).show();
}
}}

[Link]
package [Link].assignmentq20;

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

import [Link];

public class DatabaseHelper extends SQLiteOpenHelper {

private static final String DATABASE_NAME = "student_database";


private static final int DATABASE_VERSION = 1;
public static final String TABLE_NAME = "Students";
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, 1);
}

@Override
public void onCreate(SQLiteDatabase db) {
String createTableQuery = "CREATE TABLE " + TABLE_NAME + " (" +
"Roll INTEGER PRIMARY KEY, " +
"Name TEXT, " +
"Email TEXT, " +
"ContactNo TEXT, " +
"Gender TEXT, " +
"Class TEXT)";
[Link](createTableQuery);

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

public long insertStudent(int roll, String name, String email, String


contactNo, String gender, String className) {
SQLiteDatabase db = [Link]();
ContentValues values = new ContentValues();
[Link]("Roll", roll);
[Link]("Name", name);
[Link]("Email", email);
[Link]("ContactNo", contactNo);
[Link]("Gender", gender);
[Link]("Class", className);

long result = [Link](TABLE_NAME, null, values);

[Link]();
return result;
}
}

Output:-

You might also like