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

Ex 27

The document provides instructions for creating a login form in an Android application using XML and Java. It includes the layout design in 'activity_main.xml' and the logic for handling login success or failure in 'MainActivity.java'. The program displays a toast message indicating whether the login was successful or unsuccessful based on user input.

Uploaded by

Omkar Mankar
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)
16 views3 pages

Ex 27

The document provides instructions for creating a login form in an Android application using XML and Java. It includes the layout design in 'activity_main.xml' and the logic for handling login success or failure in 'MainActivity.java'. The program displays a toast message indicating whether the login was successful or unsuccessful based on user input.

Uploaded by

Omkar Mankar
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

X.

Exercise
1. Write a program to create the login form and display login successful/Unsuccessful toast message.

activity_main.xml <EditText
android:id="@+id/e2"
<?xml version="1.0" encoding="utf-8"?> android:layout_width="match_parent"
<LinearLayout android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/r
android:hint="Enter college code" />
es/android"

xmlns:app="http://schemas.android.com/apk/res- <Button
auto"
android:id="@+id/b"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:text="login" />
android:orientation="vertical"
</LinearLayout>
tools:context=".MainActivity">

MainActivity.java
<TextView
package com.example.ex2701;
android:layout_width="match_parent"
android:layout_height="wrap_content"
import
android:gravity="center" androidx.appcompat.app.AppCompatActivity;
android:text="Login" import android.view.View;
android:textColor="#000" import android.widget.Button;
android:textSize="30dp" import android.widget.EditText;
android:textStyle="bold" /> import android.widget.Toast;
import android.os.Bundle;
<EditText
android:id="@+id/e1" public class MainActivity extends
AppCompatActivity {
android:layout_width="match_parent"
android:layout_height="wrap_content"
EditText e1,e2;
android:layout_marginTop="40dp"
Button b;
android:hint="Enter college name" />
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

e1=findViewById(R.id.e1);
e2=findViewById(R.id.e2);
b=findViewById(R.id.b);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (e1.getText().toString().equals("")&& e2.getText().toString().equals(""))
{
Toast.makeText(MainActivity.this, "Login Unsuccessful",
Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(MainActivity.this, "Login Successful",
Toast.LENGTH_SHORT).show();
}
}
});
}
}
Output:

You might also like