0% found this document useful (0 votes)
2 views37 pages

PR 9

The document contains multiple Android XML layout files and Java code for a registration form application. Each layout includes fields for name, email, phone, and gender selection, with some variations in design and additional elements like a Terms and Conditions checkbox. The Java code handles user input and displays a custom toast message upon successful registration.

Uploaded by

tanujapawar940
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)
2 views37 pages

PR 9

The document contains multiple Android XML layout files and Java code for a registration form application. Each layout includes fields for name, email, phone, and gender selection, with some variations in design and additional elements like a Terms and Conditions checkbox. The Java code handles user input and displays a custom toast message upon successful registration.

Uploaded by

tanujapawar940
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

1)--

Activity_main.xml

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


<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
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"
android:gravity="center">

<EditText
android:id="@+id/etName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:padding="12dp"
android:layout_marginBottom="24dp"
android:hint="Enter Name"/>
<EditText
android:id="@+id/etEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:padding="12dp"
android:layout_marginBottom="24dp"
android:hint="Enter Email"/>
<EditText
android:id="@+id/etPhone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:padding="12dp"
android:layout_marginBottom="24dp"
android:hint="Enter Phone"/>
<Button
android:id="@+id/btnRegister"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Register"/>
</LinearLayout>
</[Link]>

[Link]

package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
[Link](this);
setContentView([Link].activity_main);

[Link](findViewById([Link]),
(v, insets) -> {
Insets systemBars =
[Link]([Link]());
[Link]([Link], [Link], [Link],
[Link]);
return insets;
});
}
}
2)—

Activity_main.xml

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


<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp">
<TextView
android:id="@+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Registration Form"
android:textSize="22sp"
android:textStyle="bold"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<EditText
android:id="@+id/etName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="Enter Name"
android:inputType="textPersonName"
android:layout_marginTop="24dp"
app:layout_constraintTop_toBottomOf="@id/tvTitle"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<EditText
android:id="@+id/etEmail"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="Enter Email"
android:inputType="textEmailAddress"
android:layout_marginTop="12dp"
app:layout_constraintTop_toBottomOf="@id/etName"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<EditText
android:id="@+id/etPhone"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="Enter Phone Number"
android:inputType="phone"
android:layout_marginTop="12dp"
app:layout_constraintTop_toBottomOf="@id/etEmail"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<Button
android:id="@+id/btnRegister"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Register"
android:layout_marginTop="24dp"
app:layout_constraintTop_toBottomOf="@id/etPhone"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
</[Link]>

[Link]

package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
[Link](this);
setContentView([Link].activity_main);

[Link](findViewById([Link]),
(v, insets) -> {
Insets systemBars =
[Link]([Link]());
[Link]([Link], [Link], [Link],
[Link]);
return insets;
});
}
}
3)--

Activity_main.xml

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


<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp">
<TextView
android:id="@+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Registration Form"
android:textSize="22sp"
android:textStyle="bold"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<EditText
android:id="@+id/etName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="Enter Name"
android:layout_marginTop="24dp"
app:layout_constraintTop_toBottomOf="@id/tvTitle"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<EditText
android:id="@+id/etEmail"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="Enter Email"
android:layout_marginTop="12dp"
app:layout_constraintTop_toBottomOf="@id/etName"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<EditText
android:id="@+id/etPhone"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="Enter Phone"
android:layout_marginTop="12dp"
app:layout_constraintTop_toBottomOf="@id/etEmail"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<TextView
android:id="@+id/tvGender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Gender"
android:textStyle="bold"
android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="@id/etPhone"
app:layout_constraintStart_toStartOf="parent"/>
<RadioGroup
android:id="@+id/rgGender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@id/tvGender"
app:layout_constraintStart_toStartOf="parent">
<RadioButton
android:id="@+id/rbMale"
android:text="Male"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RadioButton
android:id="@+id/rbFemale"
android:text="Female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RadioGroup>
<Button
android:id="@+id/btnRegister"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Register"
android:layout_marginTop="24dp"
app:layout_constraintTop_toBottomOf="@id/rgGender"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
</[Link]>

Toast_custom.xml

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


<LinearLayout
xmlns:android="[Link]
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#333333"
android:padding="12dp"
android:orientation="vertical">
<TextView
android:id="@+id/tvToast"
android:textColor="#FFFFFF"
android:textSize="16sp"
android:textStyle="bold"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>

[Link]

package [Link].pr_9_3;
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 {
EditText etName, etEmail, etPhone;
RadioGroup rgGender;
Button btnRegister;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
etName = findViewById([Link]);
etEmail = findViewById([Link]);
etPhone = findViewById([Link]);
rgGender = findViewById([Link]);
btnRegister = findViewById([Link]);
[Link](v -> {
String name = [Link]().toString().trim();
String email = [Link]().toString().trim();
String phone = [Link]().toString().trim();
int genderId = [Link]();
if ([Link]() || [Link]() || [Link]()) {
[Link](this,
"Please fill all fields",
Toast.LENGTH_SHORT).show();
return;
}
if (genderId == -1) {
[Link](this,
"Please select gender",
Toast.LENGTH_SHORT).show();
return;
}
RadioButton rb = findViewById(genderId);
String gender = [Link]().toString();
LayoutInflater inflater = getLayoutInflater();
View layout = [Link]([Link].toast_custom, null);
TextView tvToast = [Link]([Link]);
[Link]("Registered Successfully\nGender: " + gender);
Toast toast = new Toast(this);
[Link](Toast.LENGTH_LONG);
[Link](layout);
[Link]();
});
}

4)--
Activity_main.xml

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


<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp">
<TextView
android:id="@+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Registration Form"
android:textSize="22sp"
android:textStyle="bold"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<EditText
android:id="@+id/etName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="Enter Name"
android:inputType="textPersonName"
android:layout_marginTop="24dp"
app:layout_constraintTop_toBottomOf="@id/tvTitle"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<EditText
android:id="@+id/etEmail"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="Enter Email"
android:inputType="textEmailAddress"
android:layout_marginTop="12dp"
app:layout_constraintTop_toBottomOf="@id/etName"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<EditText
android:id="@+id/etPhone"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="Enter Phone"
android:inputType="phone"
android:layout_marginTop="12dp"
app:layout_constraintTop_toBottomOf="@id/etEmail"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<TextView
android:id="@+id/tvGender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Gender"
android:textStyle="bold"
android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="@id/etPhone"
app:layout_constraintStart_toStartOf="parent"/>
<RadioGroup
android:id="@+id/rgGender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@id/tvGender"
app:layout_constraintStart_toStartOf="parent">
<RadioButton
android:id="@+id/rbMale"
android:text="Male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<RadioButton
android:id="@+id/rbFemale"
android:text="Female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RadioGroup>

<CheckBox
android:id="@+id/cbTerms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I agree to Terms and Conditions"
android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="@id/rgGender"
app:layout_constraintStart_toStartOf="parent"/>
<Button
android:id="@+id/btnRegister"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Register"
android:layout_marginTop="24dp"
app:layout_constraintTop_toBottomOf="@id/cbTerms"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>

</[Link]>

Toast_custom.xml

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


<LinearLayout
xmlns:android="[Link]
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#333333"
android:padding="12dp"
android:orientation="vertical">

<TextView
android:id="@+id/tvToast"
android:textColor="#FFFFFF"
android:textSize="16sp"
android:textStyle="bold"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>

[Link]

package [Link].pr_9_4;
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 {
EditText etName, etEmail, etPhone;
RadioGroup rgGender;
CheckBox cbTerms;
Button btnRegister;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
etName = findViewById([Link]);
etEmail = findViewById([Link]);
etPhone = findViewById([Link]);
rgGender = findViewById([Link]);
cbTerms = findViewById([Link]);
btnRegister = findViewById([Link]);
[Link](v -> {String name =
[Link]().toString().trim();
String email = [Link]().toString().trim();
String phone = [Link]().toString().trim();
int genderId = [Link]();
if ([Link]() || [Link]() || [Link]()) {
[Link](this,
"Please fill all fields",
Toast.LENGTH_SHORT).show();
return;
}
if (genderId == -1) {
[Link](this,
"Please select gender",
Toast.LENGTH_SHORT).show();
return;
}
if (![Link]()) {
[Link](this,
"Please accept Terms & Conditions",
Toast.LENGTH_SHORT).show();
return;
}
RadioButton rb = findViewById(genderId);
String gender = [Link]().toString();
LayoutInflater inflater = getLayoutInflater();
View layout = [Link]([Link].toast_custom, null);
TextView tvToast = [Link]([Link]);
[Link]("Registered Successfully\nGender: " + gender);
Toast toast = new Toast(this);
[Link](Toast.LENGTH_LONG);
[Link](layout);
[Link]();
}); } }

Input Validation and FeedBack

1)--

Activity_main.xml

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


<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp">
<TextView
android:id="@+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Registration Form"
android:textSize="22sp"
android:textStyle="bold"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<EditText
android:id="@+id/etName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="Enter Name"
android:inputType="textPersonName"
android:layout_marginTop="24dp"
app:layout_constraintTop_toBottomOf="@id/tvTitle"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<EditText
android:id="@+id/etEmail"
android:layout_width="0dp"

android:layout_height="wrap_content"
android:hint="Enter Email"
android:inputType="textEmailAddress"
android:layout_marginTop="12dp"
app:layout_constraintTop_toBottomOf="@id/etName"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<EditText
android:id="@+id/etPhone"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="Enter Phone"
android:inputType="phone"
android:layout_marginTop="12dp"
app:layout_constraintTop_toBottomOf="@id/etEmail"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<TextView
android:id="@+id/tvGender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Gender"
android:textStyle="bold"
android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="@id/etPhone"
app:layout_constraintStart_toStartOf="parent"/>
<RadioGroup
android:id="@+id/rgGender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@id/tvGender"
app:layout_constraintStart_toStartOf="parent">
<RadioButton
android:id="@+id/rbMale"
android:text="Male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<RadioButton
android:id="@+id/rbFemale"
android:text="Female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RadioGroup>
<CheckBox
android:id="@+id/cbTerms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I agree to Terms and Conditions"
android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="@id/rgGender"
app:layout_constraintStart_toStartOf="parent"/>
<Button
android:id="@+id/btnRegister"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Register"
android:layout_marginTop="24dp"
app:layout_constraintTop_toBottomOf="@id/cbTerms"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
</[Link]>

[Link]

package [Link].pr_9_01;
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 {
EditText etName, etEmail, etPhone;
RadioGroup rgGender;
CheckBox cbTerms;
Button btnRegister;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

etName = findViewById([Link]);
etEmail = findViewById([Link]);
etPhone = findViewById([Link]);
rgGender = findViewById([Link]);
cbTerms = findViewById([Link]);
btnRegister = findViewById([Link]);
[Link](v -> {
String name = [Link]().toString().trim();
String email = [Link]().toString().trim();
String phone = [Link]().toString().trim();
int genderId = [Link]();
if ([Link]()) {
[Link]("Name required");
[Link]();
return;
}
if ([Link]()) {
[Link]("Email required");
[Link]();
return;
}
if ([Link]()) {
[Link]("Phone required");
[Link]();
return;
}
if (genderId == -1) {
[Link](this,
"Please select gender",
Toast.LENGTH_SHORT).show();
return;
}
if (![Link]()) {
[Link](this,
"Accept Terms & Conditions",
Toast.LENGTH_SHORT).show();
return;
}
RadioButton rb = findViewById(genderId);
String gender = [Link]().toString();
LayoutInflater inflater = getLayoutInflater();
View layout = [Link]([Link].toast_custom, null);
TextView tvToast = [Link]([Link]);
[Link]("Registration Successful");
Toast toast = new Toast(this);
[Link](Toast.LENGTH_LONG);
[Link](layout);
[Link]();
});
}
}

toast_custom.xml

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


<LinearLayout
xmlns:android="[Link]
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#333333"
android:padding="12dp"
android:orientation="vertical">
<TextView
android:id="@+id/tvToast"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:textSize="16sp"
android:textStyle="bold"/>
</LinearLayout>
2)-- Activity_main.xml

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

<[Link]

xmlns:android="[Link]

xmlns:app="[Link]

android:layout_width="match_parent"

android:layout_height="match_parent"

android:padding="20dp">

<TextView

android:id="@+id/tvTitle"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Registration Form"

android:textSize="22sp"

android:textStyle="bold"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintEnd_toEndOf="parent"/>

<EditText

android:id="@+id/etName"

android:layout_width="0dp"
android:layout_height="wrap_content"

android:hint="Enter Name"

android:inputType="textPersonName"

android:layout_marginTop="24dp"

app:layout_constraintTop_toBottomOf="@id/tvTitle"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintEnd_toEndOf="parent"/>

<EditText

android:id="@+id/etEmail"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:hint="Enter Email"

android:inputType="textEmailAddress"

android:layout_marginTop="12dp"

app:layout_constraintTop_toBottomOf="@id/etName"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintEnd_toEndOf="parent"/>

<EditText

android:id="@+id/etPhone"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:hint="Enter Phone"

android:inputType="phone"

android:layout_marginTop="12dp"

app:layout_constraintTop_toBottomOf="@id/etEmail"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintEnd_toEndOf="parent"/>

<TextView

android:id="@+id/tvGender"
android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Gender"

android:textStyle="bold"

android:layout_marginTop="16dp"

app:layout_constraintTop_toBottomOf="@id/etPhone"

app:layout_constraintStart_toStartOf="parent"/>

<RadioGroup

android:id="@+id/rgGender"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:orientation="horizontal"

android:layout_marginTop="8dp"

app:layout_constraintTop_toBottomOf="@id/tvGender"

app:layout_constraintStart_toStartOf="parent">

<RadioButton

android:id="@+id/rbMale"

android:text="Male"

android:layout_width="wrap_content"

android:layout_height="wrap_content"/>

<RadioButton

android:id="@+id/rbFemale"

android:text="Female”

android:layout_width="wrap_content"

android:layout_height="wrap_content"/>

</RadioGroup>

<CheckBox

android:id="@+id/cbTerms"

android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:text="I agree to Terms and Conditions"

android:layout_marginTop="16dp"

app:layout_constraintTop_toBottomOf="@id/rgGender"

app:layout_constraintStart_toStartOf="parent"/>

<Button

android:id="@+id/btnRegister"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:text="Register"

android:layout_marginTop="24dp"

app:layout_constraintTop_toBottomOf="@id/cbTerms"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintEnd_toEndOf="parent"/>

</[Link]>

[Link]

package [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

public class MainActivity extends AppCompatActivity {


EditText etName, etEmail, etPhone;

RadioGroup rgGender;

CheckBox cbTerms;

Button btnRegister;

@Override

protected void onCreate(Bundle savedInstanceState) {

[Link](savedInstanceState);

setContentView([Link].activity_main);

etName = findViewById([Link]);

etEmail = findViewById([Link]);

etPhone = findViewById([Link]);

rgGender = findViewById([Link]);

cbTerms = findViewById([Link]);

btnRegister = findViewById([Link]);

[Link](v -> {

String name = [Link]().toString().trim();

String email = [Link]().toString().trim();

String phone = [Link]().toString().trim();

if ([Link]()) {

[Link]("Name required");

return;

if ([Link]()) {

[Link]("Email required");

return;

if ([Link]()) {

[Link]("Phone required");

return;
}

if ([Link]() == -1) {

[Link](this, "Select gender",


Toast.LENGTH_SHORT).show();

return;

if (![Link]()) {

[Link](this, "Accept Terms & Conditions",


Toast.LENGTH_SHORT).show();

return;

LayoutInflater inflater = getLayoutInflater();

View layout = [Link]([Link].toast_custom, null);

TextView tvToast = [Link]([Link]);

[Link]("Registration Successful\nName: " + name + "\


nEmail: " + email);

Toast toast = new Toast(this);

[Link](Toast.LENGTH_LONG);

[Link](layout);

[Link]();

});

Toast_custom.xml

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

<LinearLayout
xmlns:android="[Link]

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="#333333"
android:padding="12dp"

android:orientation="vertical">

<TextView

android:id="@+id/tvToast"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textColor="#FFFFFF"

android:textSize="16sp"

android:textStyle="bold"/> </LinearLayout>

3)-> Activity_main.xml

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

<[Link]

xmlns:android="[Link]

xmlns:app="[Link]

android:layout_width="match_parent"

android:layout_height="match_parent"

android:padding="20dp">

<TextView

android:id="@+id/tvTitle"

android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:text="Registration Form"

android:textSize="22sp"

android:textStyle="bold"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintEnd_toEndOf="parent"/>

<EditText

android:id="@+id/etName"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:hint="Name"

app:layout_constraintTop_toBottomOf="@id/tvTitle"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintEnd_toEndOf="parent"

android:layout_marginTop="20dp"/>

<EditText

android:id="@+id/etEmail"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:hint="Email"

android:inputType="textEmailAddress"

app:layout_constraintTop_toBottomOf="@id/etName"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintEnd_toEndOf="parent"

android:layout_marginTop="10dp"/>

<EditText

android:id="@+id/etPhone"

android:layout_width="0dp"
android:layout_height="wrap_content"

android:hint="Phone"

android:inputType="phone"

app:layout_constraintTop_toBottomOf="@id/etEmail"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintEnd_toEndOf="parent"

android:layout_marginTop="10dp"/>

<RadioGroup

android:id="@+id/rgGender"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:orientation="horizontal"

app:layout_constraintTop_toBottomOf="@id/etPhone"

app:layout_constraintStart_toStartOf="parent"

android:layout_marginTop="15dp">

<RadioButton

android:id="@+id/rbMale"

android:text="Male"/>

<RadioButton

android:id="@+id/rbFemale"

android:text="Female"/>

</RadioGroup>

<CheckBox

android:id="@+id/cbTerms"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="I agree to Terms & Conditions"

app:layout_constraintTop_toBottomOf="@id/rgGender"

app:layout_constraintStart_toStartOf="parent"
android:layout_marginTop="10dp"/>

<Button

android:id="@+id/btnRegister"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:text="Register"

app:layout_constraintTop_toBottomOf="@id/cbTerms"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintEnd_toEndOf="parent"

android:layout_marginTop="20dp"/>

</[Link]>

[Link]

package [Link];

import [Link];

import [Link];

import [Link];

import [Link].*;

import [Link];

public class MainActivity extends AppCompatActivity {

EditText etName, etEmail, etPhone;

RadioGroup rgGender;

CheckBox cbTerms;

Button btnRegister;

@Override

protected void onCreate(Bundle savedInstanceState) {

[Link](savedInstanceState);

setContentView([Link].activity_main);

etName = findViewById([Link]);

etEmail = findViewById([Link]);
etPhone = findViewById([Link]);

rgGender = findViewById([Link]);

cbTerms = findViewById([Link]);

btnRegister = findViewById([Link]);

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

private void validateAndRegister() {

String name = [Link]().toString().trim();

String email = [Link]().toString().trim();

String phone = [Link]().toString().trim();

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

showToast("All fields are required", false);

return;

if ([Link]() == -1) {

showToast("Select gender", false);

return;

if (![Link]()) {

showToast("Accept terms & conditions", false);

return;

showToast("Welcome " + name + "\nEmail: " + email, true);

private void showToast(String message, boolean success) {

LayoutInflater inflater = getLayoutInflater();

View view = [Link]([Link].custom_toast, null);

LinearLayout layout = [Link]([Link]);

ImageView icon = [Link]([Link]);


TextView text = [Link]([Link]);

[Link](message);

if (success) {

[Link]([Link].bg_success);

[Link]([Link].ic_success);

} else {

[Link]([Link].bg_error);

[Link]([Link].ic_error);

Toast toast = new Toast(this);

[Link](view);

[Link](Toast.LENGTH_SHORT);

[Link]();

Toast_custom.xml

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

<LinearLayout
xmlns:android="[Link]

android:id="@+id/toastLayout"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:orientation="horizontal"

android:padding="15dp"

android:gravity="center">

<ImageView

android:id="@+id/toastIcon"

android:layout_width="30dp"
android:layout_height="30dp"

android:layout_marginEnd="10dp"/>

<TextView

android:id="@+id/toastText"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textSize="16sp"

android:textColor="#FFFFFF"/>

</LinearLayout>

bg_success.xml

<shape xmlns:android="[Link]
<solid android:color="#4CAF50"/>
<corners android:radius="20dp"/>
</shape>

bg_error.xml

<shape xmlns:android="[Link]
<solid android:color="#F44336"/>
<corners android:radius="20dp"/>
</shape>

4)-> Activity_main.xml

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


<[Link]

xmlns:android="[Link]

xmlns:app="[Link]

android:layout_width="match_parent"

android:layout_height="match_parent"

android:padding="20dp">

<TextView

android:id="@+id/tvTitle"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Registration Form"

android:textSize="22sp"

android:textStyle="bold"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintEnd_toEndOf="parent"/>

<EditText

android:id="@+id/etName"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:hint="Name"

app:layout_constraintTop_toBottomOf="@id/tvTitle"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintEnd_toEndOf="parent"

android:layout_marginTop="20dp"/>

<EditText

android:id="@+id/etEmail"

android:layout_width="0dp"
android:layout_height="wrap_content"

android:hint="Email"

android:inputType="textEmailAddress"

app:layout_constraintTop_toBottomOf="@id/etName"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintEnd_toEndOf="parent"

android:layout_marginTop="10dp"/>

<EditText

android:id="@+id/etPhone"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:hint="Phone"

android:inputType="number"

android:maxLength="10"

app:layout_constraintTop_toBottomOf="@id/etEmail"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintEnd_toEndOf="parent"

android:layout_marginTop="10dp"/>

<RadioGroup

android:id="@+id/rgGender"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:orientation="horizontal"

app:layout_constraintTop_toBottomOf="@id/etPhone"

app:layout_constraintStart_toStartOf="parent"

android:layout_marginTop="15dp">

<RadioButton

android:id="@+id/rbMale"

android:text="Male"/>
<RadioButton

android:id="@+id/rbFemale"

android:text="Female"/>

</RadioGroup>

<CheckBox

android:id="@+id/cbTerms"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="I agree to Terms & Conditions"

app:layout_constraintTop_toBottomOf="@id/rgGender"

app:layout_constraintStart_toStartOf="parent"

android:layout_marginTop="10dp"/>

<Button

android:id="@+id/btnRegister"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:text="Register"

app:layout_constraintTop_toBottomOf="@id/cbTerms"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintEnd_toEndOf="parent"

android:layout_marginTop="20dp"/>

</[Link]>

[Link]

package [Link];

import [Link];

import [Link];

import [Link];

import [Link].*;
import [Link];

public class MainActivity extends AppCompatActivity {

EditText etName, etEmail, etPhone;

RadioGroup rgGender;

CheckBox cbTerms;

Button btnRegister;

@Override

protected void onCreate(Bundle savedInstanceState) {

[Link](savedInstanceState);

setContentView([Link].activity_main);

etName = findViewById([Link]);

etEmail = findViewById([Link]);

etPhone = findViewById([Link]);

rgGender = findViewById([Link]);

cbTerms = findViewById([Link]);

btnRegister = findViewById([Link]);

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

} private void validateAndRegister() {

String name = [Link]().toString().trim();

String email = [Link]().toString().trim();

String phone = [Link]().toString().trim();

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

showToast("All fields are required", false);

return;

} if (![Link]("\\d{10}")) {

showToast("Phone number must be exactly 10 digits", false);

return;

} if ([Link]() == -1) {

showToast("Select gender", false);


return;

} if (![Link]()) {

showToast("Accept terms & conditions", false);

return;

} showToast("Welcome " + name + "\nEmail: " + email, true);

} private void showToast(String message, boolean success) {

View view = [Link](this)

.inflate([Link].custom_toast, null);

LinearLayout layout = [Link]([Link]);

ImageView icon = [Link]([Link]);

TextView text = [Link]([Link]);

[Link](message);

if (success) {

[Link]([Link].bg_success);

[Link]([Link].ic_success);

} else {

[Link]([Link].bg_error);

[Link]([Link].ic_error);

} Toast toast = new Toast(this);

[Link](view);

[Link](Toast.LENGTH_SHORT);

[Link]();

}}

toast_custom.xml

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

<LinearLayout
xmlns:android="[Link]

android:id="@+id/toastLayout"

android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:orientation="horizontal"

android:padding="15dp"

android:gravity="center">

<ImageView

android:id="@+id/toastIcon"

android:layout_width="30dp"

android:layout_height="30dp"

android:layout_marginEnd="10dp"/>

<TextView

android:id="@+id/toastText"

android:textColor="#FFFFFF"

android:textSize="16sp"

android:layout_width="wrap_content"

android:layout_height="wrap_content"/>

</LinearLayout>

bg_error.xml

<shape xmlns:android=”[Link]
<solid android:color=”#F44336”/>
<corners android:radius=”20dp”/>
</shape>

bg_success.xml

<shape xmlns:android="[Link]
<solid android:color="#4CAF50"/>
<corners android:radius="20dp"/>
</shape>

output

You might also like