0% found this document useful (0 votes)
15 views4 pages

Practical No. 10

The document contains code for creating a login form for both a student registration system and a social networking site in Android. It includes XML layout files and Java code for handling user input and verifying login credentials. The login functionality checks if the entered username and password match predefined values and displays appropriate Toast messages based on the verification result.

Uploaded by

ganeshkumbhar638
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)
15 views4 pages

Practical No. 10

The document contains code for creating a login form for both a student registration system and a social networking site in Android. It includes XML layout files and Java code for handling user input and verifying login credentials. The login functionality checks if the entered username and password match predefined values and displays appropriate Toast messages based on the verification result.

Uploaded by

ganeshkumbhar638
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/ 4

Q.

Write a program to create a login form for android:fontFamily="times new roman"


student registration system. android:layout_marginBottom="15dp"/>
<Button
activity_main.xml
android:id="@+id/btn"
<?xml version="1.0" encoding="utf-8"?> android:layout_width="wrap_content"
<LinearLayout android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/ android:text="Login"
res/android" android:fontFamily="times new roman"
android:paddingHorizontal="50dp"
xmlns:app="http://schemas.android.com/apk/res- android:onClick="verify"/>
auto"
</LinearLayout>
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main" MainActivity.java
android:layout_width="match_parent"
android:layout_height="match_parent" package com.example.practicalno10_1;
android:orientation="vertical"
android:layout_margin="30dp" import static
android:gravity="center" android.widget.Toast.LENGTH_SHORT;
tools:context=".MainActivity">
import android.os.Bundle;
<TextView import android.view.View;
android:layout_width="match_parent" import android.widget.Button;
android:layout_height="wrap_content" import android.widget.EditText;
android:text="Student Login" import android.widget.Toast;
android:fontFamily="times new roman"
android:textSize="30dp" import androidx.activity.EdgeToEdge;
android:textStyle="bold" import
android:gravity="center"/> androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
<EditText import androidx.core.view.ViewCompat;
android:id="@+id/e1" import
android:layout_width="match_parent" androidx.core.view.WindowInsetsCompat;
android:layout_height="wrap_content"
android:hint="Enter username" public class MainActivity extends
android:fontFamily="times new roman" AppCompatActivity {
android:layout_marginBottom="15dp"/>
<EditText EditText e1,e2;
android:id="@+id/e2" Button btn;
android:layout_width="match_parent" String user = "Admin";
android:layout_height="wrap_content" String pass = "123";
android:hint="Enter password"
@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);

e1 = findViewById(R.id.e1);
e2 = findViewById(R.id.e2);
btn = findViewById(R.id.btn);
}
public void verify(View view){
String eu = e1.getText().toString();
String ep = e2.getText().toString();
if(eu.equals(user) && ep.equals(pass)){
Toast.makeText(this,"Login
Successfully!!",Toast.LENGTH_SHORT).show(
);
}
else {
Toast.makeText(this,"Login
Fails!!",Toast.LENGTH_SHORT).show();
}
}

}
Q. Write a program to create a login form for a android:layout_width="match_parent"
social networking site. android:layout_height="wrap_content">
<TextView
activity_main.xml android:layout_width="wrap_content"
android:layout_height="wrap_content"
<?xml version="1.0" encoding="utf-8"?> android:textSize="20dp"
<LinearLayout android:fontFamily="times new roman"
xmlns:android="http://schemas.android.com/apk/res android:text="Password : "/>
/android" <EditText
xmlns:app="http://schemas.android.com/apk/res- android:id="@+id/e2"
auto" android:inputType="textPassword"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:id="@+id/main" android:layout_height="wrap_content"
android:layout_width="match_parent" android:layout_marginBottom="15dp"/>
android:layout_height="match_parent" </LinearLayout>
android:orientation="vertical" <Button
android:layout_margin="30dp" android:id="@+id/btn"
android:gravity="center" android:layout_width="wrap_content"
tools:context=".MainActivity"> android:layout_height="wrap_content"
android:text="Sign in"
<ImageView android:fontFamily="times new roman"
android:layout_width="match_parent" android:paddingHorizontal="80dp"
android:layout_height="80dp" android:onClick="verify"/>
android:src="@drawable/img"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent" MainActivity.java
android:layout_height="wrap_content">
<TextView package com.example.practicalno10_2;
android:layout_width="wrap_content"
android:layout_height="wrap_content" import static
android:text="Username" android.widget.Toast.LENGTH_SHORT;
android:textSize="20dp"
android:fontFamily="times new roman"/> import android.os.Bundle;
<EditText import android.view.View;
android:id="@+id/e1" import android.widget.Button;
android:layout_width="match_parent" import android.widget.EditText;
android:layout_height="wrap_content" import android.widget.Toast;
android:fontFamily="times new roman"
android:layout_marginBottom="15dp"/> import androidx.activity.EdgeToEdge;
</LinearLayout> import
<LinearLayout androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import
androidx.core.view.WindowInsetsCompat;

public class MainActivity extends


AppCompatActivity {

EditText e1,e2;
Button btn;
String user = "Admin";
String pass = "123";

@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);

e1 = findViewById(R.id.e1);
e2 = findViewById(R.id.e2);
btn = findViewById(R.id.btn);
}
public void verify(View view){
String eu = e1.getText().toString();
String ep = e2.getText().toString();
if(eu.equals(user) && ep.equals(pass)){
Toast.makeText(this,"Login
Successfully!!",Toast.LENGTH_SHORT).show(
);
}
else {
Toast.makeText(this,"Login
Fails!!",Toast.LENGTH_SHORT).show();
}
}

You might also like