0% found this document useful (0 votes)
85 views7 pages

Exp 28

The document contains code for a login screen Android application. It includes an XML layout file defining the user interface with fields for email, password and a login button. The Java code handles clicking the login button by validating the email and password and navigating to a new activity if credentials match, or displaying errors if invalid. An empty activity is defined as the destination for valid logins.

Uploaded by

Yash Balotiya
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)
85 views7 pages

Exp 28

The document contains code for a login screen Android application. It includes an XML layout file defining the user interface with fields for email, password and a login button. The Java code handles clicking the login button by validating the email and password and navigating to a new activity if credentials match, or displaying errors if invalid. An empty activity is defined as the destination for valid logins.

Uploaded by

Yash Balotiya
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
You are on page 1/ 7

Exp 28

Xml file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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/User_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Password:"
android:inputType="textPassword"
android:layout_below="@+id/User_email"
android:layout_marginTop="50dp"
android:padding="10dp"/>

<TextView
android:id="@+id/User_Text"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:textSize="40dp"
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="User Login"/>

<Button
android:id="@+id/User_login"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@+id/User_password"
android:layout_marginTop="50dp"
android:text="Login"/>

<EditText
android:id="@+id/User_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/User_Text"
android:layout_marginTop="50dp"
android:hint="Email:"
android:padding="10dp"
android:inputType="textEmailAddress"/>

</RelativeLayout>

Java code
package com.example.exp_28;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.icu.text.UnicodeSetSpanner;
import android.os.Bundle;
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 {


Button login;
EditText Uemail,Upass;
public String Uuseremail,Upassword;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

login = findViewById(R.id.User_login);
login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
check();
}
});

Uemail = findViewById(R.id.User_email);
Upass = findViewById(R.id.User_password);
}

public void check(){


Uuseremail = Uemail.getText().toString().trim();
Upassword = Upass.getText().toString().trim();

if(Uuseremail.isEmpty()) {
Uemail.setError("Enter an e-mail,it is blank");
Uemail.requestFocus();
return;
}
if(!Patterns.EMAIL_ADDRESS.matcher(Uuseremail).matches()){
Uemail.setError("Enter an e-mail");
Uemail.requestFocus();
return;
}
if(Upassword.isEmpty()) {
Upass.setError("Enter a password , it is blank");
Upass.requestFocus();
return;
}
if(Upassword.length()<6){
Upass.setError("Minimum length is 6 characters");
Upass.requestFocus();
return;
}
if(Uuseremail.equals("sonali.pawar@ves.ac.in") &&
Upassword.equals(“123abc")){
Toast.makeText(MainActivity.this,"Welcome
User",Toast.LENGTH_LONG).show();
Intent intent = new
Intent(MainActivity.this,Empty_Activity.class);
startActivity(intent);
}
else{
Toast.makeText(this,"Wrong email or
password",Toast.LENGTH_LONG).show();
}
}
}

empty activity
<?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=".Empty_Activity">

</androidx.constraintlayout.widget.ConstraintLayout>

Java
package com.example.exp_28;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class Empty_Activity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_empty);
}
}

output

You might also like