Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

21bca0022 Da1 Mad

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

NAME: RIYANSHI KEDIA

REG NO. – 21BCA0022


DIGITAL ASSINGMENT 1
MOBILE APPLICATION DEVELOPMENT

XML FILE:
<?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"
android:background="@drawable/ic_launcher_foreground"
>

<EditText
android:id="@+id/firstName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginTop="50dp"
android:layout_marginEnd="40dp"
android:layout_marginBottom="10dp"
android:ems="10"
android:inputType="text"
android:text=""
app:layout_constraintBottom_toTopOf="@+id/lastName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/textView2"
app:layout_constraintTop_toTopOf="parent" />

<EditText
android:id="@+id/lastName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginTop="40dp"
android:layout_marginEnd="30dp"
android:layout_marginBottom="70dp"
android:ems="10"
android:inputType="text"
android:text=""
app:layout_constraintBottom_toTopOf="@+id/address"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/textView3"
app:layout_constraintTop_toBottomOf="@+id/firstName" />

<EditText
android:id="@+id/address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="81dp"
android:layout_marginTop="2dp"
android:layout_marginEnd="38dp"
android:layout_marginBottom="150dp"
android:ems="10"
android:inputType="text"
android:text=""
app:layout_constraintBottom_toTopOf="@+id/email"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/textView4"
app:layout_constraintTop_toBottomOf="@+id/lastName" />

<EditText
android:id="@+id/email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="51dp"
android:layout_marginBottom="10dp"
android:ems="10"
android:inputType="textEmailAddress"
app:layout_constraintBottom_toTopOf="@+id/radioButton2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.458"
app:layout_constraintStart_toEndOf="@+id/textView4"
app:layout_constraintTop_toBottomOf="@+id/textView5"
app:layout_constraintVertical_bias="0.333" />

<Button
android:id="@+id/register"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="78dp"
android:layout_marginTop="40dp"
android:layout_marginEnd="21dp"
android:layout_marginBottom="34dp"
android:text="Register"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/radioButton2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/radioButton" />

<RadioButton
android:id="@+id/radioButton"
android:layout_width="102dp"
android:layout_height="41dp"
android:layout_marginStart="81dp"
android:layout_marginTop="30dp"
android:layout_marginEnd="71dp"
android:layout_marginBottom="92dp"
android:text="Male"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/radioButton2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/email" />

<RadioButton
android:id="@+id/radioButton2"
android:layout_width="116dp"
android:layout_height="37dp"
android:layout_marginStart="70dp"
android:layout_marginTop="47dp"
android:layout_marginEnd="92dp"
android:layout_marginBottom="125dp"
android:text="Female"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/radioButton"
app:layout_constraintTop_toBottomOf="@+id/email" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginTop="57dp"
android:layout_marginEnd="44dp"
android:layout_marginBottom="35dp"
android:text="First name:"
app:layout_constraintBottom_toTopOf="@+id/textView3"
app:layout_constraintEnd_toStartOf="@+id/firstName"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginTop="30dp"
android:layout_marginEnd="44dp"
android:layout_marginBottom="105dp"
android:text="Last Name:"
app:layout_constraintBottom_toTopOf="@+id/textView4"
app:layout_constraintEnd_toStartOf="@+id/lastName"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2" />

<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="84dp"
android:layout_marginTop="2dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="102dp"
android:text="Address:"
app:layout_constraintBottom_toTopOf="@+id/textView5"
app:layout_constraintEnd_toStartOf="@+id/textView5"
app:layout_constraintHorizontal_bias="0.456"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView3" />

<TextView
android:id="@+id/textView5"
android:layout_width="72dp"
android:layout_height="20dp"
android:layout_marginTop="74dp"
android:layout_marginEnd="28dp"
android:layout_marginBottom="152dp"
android:text="Email:"
app:layout_constraintBottom_toTopOf="@+id/radioButton"
app:layout_constraintEnd_toStartOf="@+id/email"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView4" />
</androidx.constraintlayout.widget.ConstraintLayout>
JAVA FILE:
package com.cs.registrationform;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Patterns;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
firstName = findViewById(R.id.firstName);
lastName = findViewById(R.id.lastName);
address = findViewById(R.id.address);
email = findViewById(R.id.email);
register = findViewById(R.id.register);
radioButton = findViewById(R.id.radioButton);
radioButton2 = findViewById(R.id.radioButton2);
register.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view ){
checkDataEntered();
}
});
}
EditText firstName;
EditText lastName;
EditText address;
EditText email;
Button register;
Button radioButton;
Button radioButton2;
boolean isEmpty(EditText text) {
CharSequence str = text.getText().toString();
return TextUtils.isEmpty(str);

}
void checkDataEntered(){
if (isEmpty(firstName)) {
Toast t = Toast.makeText(this, "You must enter first name to register!",
Toast.LENGTH_SHORT);
t.show();
}
if (isEmpty(lastName)) {
lastName.setError("Last name is required!");
}
if (isEmail(email) == false) {
email.setError("Enter valid email!");
}
}
boolean isEmail(EditText text) {
CharSequence email = text.getText().toString();
return (!TextUtils.isEmpty(email) &&
Patterns.EMAIL_ADDRESS.matcher(email).matches());
}

}
OUTPUT AND DESIGN:

You might also like