0% found this document useful (0 votes)
216 views5 pages

Login Form with Toast Feedback

This document describes a login form with toast message functionality in Android. It includes the XML layout code for the login form widgets like text views, edit texts and a button. It also includes the Java code for the activity class that initializes the form, authenticates the login by comparing the entered username and password to hardcoded values, and displays a toast message on successful or unsuccessful login.

Uploaded by

Rehan Pathan
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)
216 views5 pages

Login Form with Toast Feedback

This document describes a login form with toast message functionality in Android. It includes the XML layout code for the login form widgets like text views, edit texts and a button. It also includes the Java code for the activity class that initializes the form, authenticates the login by comparing the entered username and password to hardcoded values, and displays a toast message on successful or unsuccessful login.

Uploaded by

Rehan Pathan
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
  • Activity_main.xml Overview
  • XML Layout Details
  • Java Integration Setup
  • Java Code Implementation
  • Testing and Debugging

Login Form with Toast Message

Activity_main.xml

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

<RelativeLayout
xmlns:android="[Link]

xmlns:app="[Link]

xmlns:tools="[Link]

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity">

<TextView

android:id="@+id/textView1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Authentication Required"/>

<TextView

android:id="@+id/textView2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:text="Username:" />

<EditText

android:id="@+id/usernameET"

android:layout_width="wrap_content"

android:layout_height="wrap_content" />

<TextView

android:id="@+id/textView3"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Password:" />

<EditText

android:id="@+id/passwordET"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:hint="testpass"

android:inputType="textPassword" />

<Button

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

android:layout_height="wrap_content"

android:layout_below="@+id/passwordET"

android:layout_centerHorizontal="true"

android:layout_marginTop="94dp"

android:onClick="authenticateLogin"

android:text="Login"

tools:ignore="OnClick" />

</RelativeLayout>

[Link]

package [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {

private EditText username;

private EditText password;

private Button login;

@Override

protected void onCreate(Bundle savedInstanceState) {

[Link](savedInstanceState);

setContentView([Link].activity_main);

setupVariables();

public void authenticateLogin(View view) {

if ([Link]().toString().equals("admin") &&

[Link]().toString().equals("admin123")) {

[Link](getApplicationContext(), "Login Successful!",

Toast.LENGTH_SHORT).show();

} else {

[Link](getApplicationContext(), "Login Unsuccessful!",


Toast.LENGTH_SHORT).show();

private void setupVariables() {

username = (EditText) findViewById([Link]);

password = (EditText) findViewById([Link]);

login = (Button) findViewById([Link]);

You might also like