Android Practical .
Android Practical .
Std:- TYBBA(CA).
Div – B
Enroll no:- 2103458
Roll no:- 32177
Subject :- Android Practical Assignment.
<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" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
package com.example.assignmentq1;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
OutPut:-
Q2. Design screen to send email (compose email) using linear layout.
Ans:-
Activity_main.xml
<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>
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
package com.example.assignmentq2;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
OutPut:
<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>
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
package com.example.assignmentq3;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
OutPut:
<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" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.xml
package com.example.assigmentq4;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
num = findViewById(R.id.enternumber);
check = findViewById(R.id.checkbtn);
check.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int n;
n = Integer.parseInt(num.getText().toString());
if(n%2==0)
{
Toast.makeText(MainActivity.this, "Even",
Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(MainActivity.this, "Odd",
Toast.LENGTH_SHORT).show();
}
}
});
}
}
OutPut:-
<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" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
package com.example.assignment5;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
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"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
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" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
package com.example.assigmentq6;
import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
EditText txt;
Button btnup,btnlow;
TextView result ;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txt = findViewById(R.id.enterstring);
btnup =findViewById(R.id.btnupper);
btnlow = findViewById(R.id.btnlower);
result = findViewById(R.id.Result);
btnup.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String str;
str = txt.getText().toString();
result.setText(str.toUpperCase());
}
});
btnlow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String str;
str = txt.getText().toString();
result.setText(str.toLowerCase());
}
});
}
}
Output:-
Q7. Create a Simple Application Which Shows Life Cycle of Activity.
Ans:-
Acitivity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
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" />
</androidx.constraintlayout.widget.ConstraintLayout>
Activity2_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
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" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java:
package com.example.assignmentq7;
import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
Button bt1 ;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bt1 = findViewById(R.id.btnclick);
bt1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent int1 = new Intent(getApplicationContext(),
activity2.class);
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"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
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" />
</androidx.constraintlayout.widget.ConstraintLayout>
Activity_resultpage.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
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" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
package com.example.assignmentq8;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
resultpage.java
package com.example.assignmentq8;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_resultpage);
t1 = findViewById(R.id.Result);
Bundle bd2 = getIntent().getExtras();
if (bd2 != null) {
String str = bd2.getString("msg");
if (str != null) {
t1.setText("Your Message " + str);
} else {
t1.setText("No message received");
}
}
}
}
Output:-
Q9. Create simple application with Login Screen. On successful
login, gives message go to next Activity (Without Using Database).
Ans:-
AcitivityMain.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
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" />
</androidx.constraintlayout.widget.ConstraintLayout>
Activity_login.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
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" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
package com.example.assignmentq9;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
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) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ed1user = findViewById(R.id.username);
ed2pass =findViewById(R.id.password);
b1 = findViewById(R.id.loginbtn);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String username = ed1user.getText().toString();
String password = ed2pass.getText().toString();
if(username.equals(Correct_Username)&&password.equals(Correct_Password))
{
Toast.makeText(MainActivity.this, "Login Successfully",
Toast.LENGTH_LONG).show();
Intent intent = new Intent(MainActivity.this,
LoginActivity.class);
startActivity(intent);
}
else {
Toast.makeText(MainActivity.this, "Invalid Password",
Toast.LENGTH_LONG).show();
}
}
});
}
}
LoginActivity.xml
package com.example.assignmentq9;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.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:- MainActivity.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
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" />
</androidx.constraintlayout.widget.ConstraintLayout>
ActivityOutput.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
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" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
package com.example.assignmentq10;
import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
EditText ed1, ed2, ed3, ed4,ed5, ed6;
Button b1;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ed1 = findViewById(R.id.fname);
ed2 = findViewById(R.id.mname);
ed3 = findViewById(R.id.lname);
ed4 = findViewById(R.id.dob);
ed5 = findViewById(R.id.Email);
ed6 = findViewById(R.id.address);
b1 = findViewById(R.id.Submitbtn);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String fname, mname, lname, dob, email, address;
fname = ed1.getText().toString();
mname = ed2.getText().toString();
lname = ed3.getText().toString();
dob = ed4.getText().toString();
email = ed5.getText().toString();
address = ed6.getText().toString();
OutputActivity.java
package com.example.assignmentq10;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
}
}
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:-
ActivityInfo.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
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" />
</androidx.constraintlayout.widget.ConstraintLayout>
ActivityResult.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
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" />
</androidx.constraintlayout.widget.ConstraintLayout>
InfoActivity.java
package com.example.assignmentq11;
import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class InfoActivity extends AppCompatActivity {
EditText ed1,ed2,ed3, ed4, ed5, ed6;
Button b1;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_info);
ed1 = findViewById(R.id.adharNo);
ed2 = findViewById(R.id.userName);
ed3 = findViewById(R.id.Dateofbirth);
ed4 = findViewById(R.id.Gender);
ed5 = findViewById(R.id.Address);
ed6 = findViewById(R.id.contact);
b1 = findViewById(R.id.Submitbtn);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String adno = ed1.getText().toString();
String user = ed2.getText().toString();
String dateofbirth = ed3.getText().toString();
String Gender = ed4.getText().toString();
String address = ed5.getText().toString();
String contact = ed6.getText().toString();
Result.Java
package com.example.assignmentq11;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class Result extends AppCompatActivity {
TextView t1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_result);
Bundle bundle = getIntent().getExtras();
String adno = bundle.getString("1");
String user = bundle.getString("2");
String dateofbirth = bundle.getString("3");
String gender = bundle.getString("4");
String address = bundle.getString("5");
String contact = bundle.getString("6");
TextView tv1 = findViewById(R.id.tv1);
tv1.setText("Adhar No: " + adno + "\n" +
"User: " + user + "\n" +
"Date of Birth: " + dateofbirth + "\n" +
"Gender: " + gender + "\n" +
"Address: " + address + "\n" +
"Contact: " + contact);
}
}
Output
12.Design Following Screens Using Radio/buttons & CheckBoxes.
Display the selected text using Toast.
Ans:-
ActivityMain.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
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" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
package com.example.assignq12;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RadioGroup radioGroup = findViewById(R.id.rg1);
CheckBox cppCheckBox = findViewById(R.id.cpp);
CheckBox dsCheckBox = findViewById(R.id.ds);
CheckBox csharpCheckBox = findViewById(R.id.csharp);
CheckBox javaCheckBox = findViewById(R.id.java);
displayBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
displaySelectedOptions(radioGroup, cppCheckBox, dsCheckBox,
csharpCheckBox, javaCheckBox);
}
});
clearBtn.setOnClickListener(new View.OnClickListener() {
@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)
{
radioGroup.clearCheck();
cppCheckBox.setChecked(false);
dsCheckBox.setChecked(false);
csharpCheckBox.setChecked(false);
javaCheckBox.setChecked(false);
}
private void showToast(String message) {
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
}
}
Output:-
<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>
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
package com.example.formapplication;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initialize your views
editFirstName = findViewById(R.id.editfname);
editLastName = findViewById(R.id.editlastname);
editAddress = findViewById(R.id.editaddress);
editPhone = findViewById(R.id.editphone);
editEmail = findViewById(R.id.editemail);
radioMale = findViewById(R.id.r1male);
radioFemale = findViewById(R.id.r2female);
submitButton = findViewById(R.id.b1submit);
clearButton = findViewById(R.id.b2clear);
textViewDetails = findViewById(R.id.Results);
//textViewDetails = findViewById(R.id.textViewDetails); // assuming
you have a TextView with this ID
<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" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
package com.example.assignmentq14;
import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.DatePicker;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
EditText ed1;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ed1 = findViewById(R.id.editTextText);
ed1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DatePickerDialog dtp = new
DatePickerDialog(MainActivity.this, AlertDialog.THEME_HOLO_DARK);
dtp.setOnDateSetListener(new
DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int
month, int dayOfMonth) {
ed1.setText(dayOfMonth+"/"+(year+1)+"/"+month);
}
});
dtp.show();
}
});
}
}
Output:-
15. Create an application to demonstrate list view using adapters.
Ans:-
ActivityMain.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
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" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
package com.example.assignmentq15;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import java.util.ArrayList;
l1.setAdapter(adapter);
l1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int
position, long id) {
it.add(adapter1.getItem(position).toString());
}
});
}
}
Output:-
Ans:- ActivityMain.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
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" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
package com.example.assignmentq16;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
Spinner spBank;
String[] bank = {"BOI", "SBI", "HDFC", "PNB", "OBC"};
String bk;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
spBank = findViewById(R.id.spinner1);
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
android.R.layout.simple_expandable_list_item_1, bank);
spBank.setAdapter(adapter);
spBank.setOnItemSelectedListener(new
AdapterView.OnItemSelectedListener() {
@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:-
<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>
MainActivity.java
package com.example.assignmentq17;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
public class MainActivity extends AppCompatActivity {
private static final String FILE_NAME = "test.txt";
private Button writeButton, readButton;
private TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
writeButton = findViewById(R.id.writeButton);
readButton = findViewById(R.id.readButton);
textView = findViewById(R.id.textView);
}
public void writeToFile(View view) {
String content = "Hello, this is the content of the file.";
try (FileOutputStream fos = openFileOutput(FILE_NAME,
Context.MODE_PRIVATE)) {
fos.write(content.getBytes());
textView.setText("File written successfully.");
} catch (IOException e) {
e.printStackTrace();
textView.setText("Error writing to file.");
}
}
Output:-
18. Create an Android App that creates a file test.txt in Internal
Storage. On click of Reverse button display the content of test.txt in
reverse order.
Ans:-
ActivityMain.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
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>
MainActivity.java
package com.example.assignmentq18;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
writeButton = findViewById(R.id.writeButton);
reverseButton = findViewById(R.id.reverseButton);
textView = findViewById(R.id.textView);
}
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:-
ActivityMain.java
<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>
ActivitySecond.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
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>
DataBaseHelper.java
package com.example.assignmentq19;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import androidx.annotation.Nullable;
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE Login (Username TEXT PRIMARY KEY, Password
TEXT)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int
newVersion) {
}
public boolean checkLogin(String username, String password) {
SQLiteDatabase db = this.getReadableDatabase();
String query = "SELECT * FROM Login WHERE Username=? AND
Password=?";
Log.d("LoginCheck", "Query: " + query);
Cursor cursor = db.rawQuery(query, new String[]{username,
password});
boolean isValid = cursor.getCount() > 0;
Log.d("LoginCheck", "isValid: " + isValid);
cursor.close();
db.close();
return isValid;
}
}
MainActivity.java
package com.example.assignmentq19;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editTextUsername = findViewById(R.id.editTextUsername);
editTextPassword = findViewById(R.id.editTextPassword);
if (databaseHelper.checkLogin(username, password)) {
// Successful login
Intent intent = new Intent(this, secondactivity.class);
intent.putExtra("USERNAME", username);
startActivity(intent);
} else {
// Failed login
Toast.makeText(this, "Invalid username or password",
Toast.LENGTH_SHORT).show();
}
}
}
SecondActivity.java
package com.example.assignmentq19;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_secondactivity);
}
}
Output:
20. Create an application to insert student information(Roll, Name,
email,contact no, gender,class) to the database.
Ans:-
ActivityMain.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
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>
MainActivity.java
package com.example.assignmentq20;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
}
public void insertStudent(View view) {
int roll =
Integer.parseInt(editTextRoll.getText().toString().trim());
String name = editTextName.getText().toString().trim();
String email = editTextEmail.getText().toString().trim();
String contactNo = editTextContactNo.getText().toString().trim();
String className = editTextClass.getText().toString().trim();
RadioButton selectedGenderRadioButton =
findViewById(radioGroupGender.getCheckedRadioButtonId());
String gender = selectedGenderRadioButton.getText().toString();
if (result != -1) {
// Student inserted successfully
Toast.makeText(this, "Student information inserted
successfully", Toast.LENGTH_SHORT).show();
} else {
// Error inserting student
Toast.makeText(this, "Error inserting student information",
Toast.LENGTH_SHORT).show();
}
}}
DatabaseHelper.java
package com.example.assignmentq20;
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import androidx.annotation.Nullable;
@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)";
db.execSQL(createTableQuery);
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int
newVersion) {
db.close();
return result;
}
}
Output:-