0% found this document useful (0 votes)
50 views3 pages

Practical 27

The document shows code for creating a login form with XML layout and Java code. It includes EditText fields for username and password, a button to login, and toast messages to display if login is successful or unsuccessful by comparing the entered values to hardcoded values.

Uploaded by

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

Practical 27

The document shows code for creating a login form with XML layout and Java code. It includes EditText fields for username and password, a button to login, and toast messages to display if login is successful or unsuccessful by comparing the entered values to hardcoded values.

Uploaded by

Nisha Parchande
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Practical – 27

Q1) WAP to create the login form and display login successful/ unsuccessful toast
message.
XML CODE:-
<?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_marginStart="99dp"
android:layout_marginTop="106dp"
android:text="Login"
android:textSize="29dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<EditText
android:id="@+id/ett1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="1dp"
android:ems="10"
android:hint="Enter your name"
android:inputType="text"
android:textSize="16dp"
app:layout_constraintStart_toStartOf="@+id/textView"
app:layout_constraintTop_toBottomOf="@+id/textView" />

<EditText
android:id="@+id/ett22"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:ems="10"
android:hint="Enter password"
android:inputType="textPassword"
android:textSize="16dp"
app:layout_constraintStart_toStartOf="@+id/ett1"
app:layout_constraintTop_toBottomOf="@+id/ett1" />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="61dp"
android:layout_marginEnd="14dp"
android:text="LOGIN"
android:textSize="30dp"
app:layout_constraintEnd_toEndOf="@+id/ett22"
app:layout_constraintTop_toBottomOf="@+id/ett22" />

</androidx.constraintlayout.widget.ConstraintLayout>

JAVA CODE:-
package com.example.prac27;
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.Toast;

public class MainActivity extends AppCompatActivity {


Button btn;
EditText et1, et2;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = findViewById(R.id.button);
et1 = findViewById(R.id.ett1);
et2 = findViewById(R.id.ett22);
btn.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
passwdCheck();
}
});
}
public void passwdCheck(){
if(et1.getText().toString().equals("Admin")&&et2.getText().toString().equals("1234")){
Toast.makeText(MainActivity.this,"Login Successfull",Toast.LENGTH_LONG).show();
}else{
Toast.makeText(MainActivity.this,"Please Check username and password",Toast.LENGTH_LONG).show();
}
}
}

You might also like