Mad 10
Mad 10
android:layout_below="@id/editTextPassword"/
</>activity_main.xml
>
<?xml version="1.0" encoding="utf-8"?>
</RelativeLayout>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/
res/android" Java Code
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" package com.example.task4;
android:layout_height="match_parent" import android.os.Bundle;
android:padding="16dp" import android.view.View;
tools:context=".MainActivity"> import android.widget.Button;
<EditText import android.widget.EditText;
android:id="@+id/editTextUsername" import android.widget.Toast;
android:layout_width="match_parent" import
androidx.appcompat.app.AppCompatActivity;
android:layout_height="wrap_content"
public class MainActivity extends
android:hint="Username"
AppCompatActivity {
android:layout_marginBottom="8dp"/>
private EditText editTextUsername;
<EditText
private EditText editTextPassword;
android:id="@+id/editTextPassword"
private Button buttonLogin;
android:layout_width="match_parent"
@Override
android:layout_height="wrap_content"
protected void onCreate(Bundle
android:hint="Password" savedInstanceState) {
android:inputType="textPassword" super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
android:layout_below="@id/editTextUsername"
// Initialize views
android:layout_marginBottom="16dp"/>
editTextUsername =
<Button findViewById(R.id.editTextUsername);
android:id="@+id/buttonLogin" editTextPassword =
findViewById(R.id.editTextPassword);
android:layout_width="match_parent"
buttonLogin =
android:layout_height="wrap_content" findViewById(R.id.buttonLogin);
android:text="Login" // Set click listener for the login button
buttonLogin.setOnClickListener(new
View.OnClickListener() {
@Override android:layout_width="match_parent"
public void onClick(View v) { android:layout_height="match_parent"
// Retrieve username and password android:padding="16dp"
entered by the user
tools:context=".MainActivity">
String username =
<TextView
editTextUsername.getText().toString();
android:layout_width="wrap_content"
String password =
editTextPassword.getText().toString(); android:layout_height="wrap_content"
// Check if username and password are android:text="Login"
valid (For simplicity, hardcoding the credentials)
android:textSize="24sp"
if (username.equals("admin") &&
password.equals("password")) { android:layout_centerHorizontal="true"
<RelativeLayout android:id="@+id/login_button"
xmlns:android="http://schemas.android.com/apk/ android:layout_width="match_parent"
res/android"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools" android:text="Login"
<EditText
android:layout_below="@id/password_input"
android:id="@+id/register_username_input"
android:layout_marginTop="20dp"/>
android:layout_width="match_parent"
<TextView
android:layout_height="wrap_content"
android:id="@+id/register_link"
android:hint="Username"
android:layout_width="wrap_content"
android:layout_below="@id/register_text"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"/>
android:text="Don't have an account?
<EditText
Register here"
android:textColor="@android:color/holo_blue_d android:id="@+id/register_password_input"
ark"
android:layout_width="match_parent"
android:layout_below="@id/login_button"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:hint="Password"
android:layout_centerHorizontal="true"/>
android:inputType="textPassword"
</RelativeLayout>
android:layout_below="@id/register_username_i
nput"
android:layout_marginTop="10dp"/>
activity_register.xml
<EditText
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/ android:id="@+id/register_email_input"
res/android"
android:layout_width="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:hint="Email"
android:layout_height="match_parent"
android:inputType="textEmailAddress"
android:padding="16dp"
android:layout_below="@id/register_password_i
tools:context=".RegisterActivity"> nput"
<TextView android:layout_marginTop="10dp"/>
android:layout_width="wrap_content" <Button
android:layout_height="wrap_content" android:id="@+id/register_button"
android:text="Register" android:layout_width="match_parent"
android:textSize="24sp" android:layout_height="wrap_content"
android:layout_centerHorizontal="true" android:text="Register"
android:id="@+id/register_text"/>
setContentView(R.layout.activity_main);
android:layout_below="@id/register_email_inpu
TextView registerLink =
t"
findViewById(R.id.register_link);
android:layout_marginTop="20dp"/>
registerLink.setOnClickListener(new
<TextView View.OnClickListener() {
android:id="@+id/login_link" @Override
android:layout_width="wrap_content" public void onClick(View v) {
android:layout_height="wrap_content" startActivity(new
Intent(MainActivity.this, RegisterActivity.class));
android:text="Already have an account?
Login here" }
});
android:textColor="@android:color/holo_blue_d
Button loginButton =
ark"
findViewById(R.id.login_button);
loginButton.setOnClickListener(new
android:layout_below="@id/register_button"
View.OnClickListener() {
android:layout_marginTop="20dp"
@Override
android:layout_centerHorizontal="true"/>
public void onClick(View v) {
</RelativeLayout>
// Add your login logic here
}
Java Code
});
// MainActivity.java
}
package com.example.studentregistrationsystem;
}
import
androidx.appcompat.app.AppCompatActivity;
// RegisterActivity.java
import android.content.Intent;
package com.example.studentregistrationsystem;
import android.os.Bundle;
import
import android.view.View;
androidx.appcompat.app.AppCompatActivity;
import android.widget.Button;
import android.os.Bundle;
import android.widget.TextView;
import android.view.View;
public class MainActivity extends
import android.widget.Button;
AppCompatActivity {
import android.widget.TextView;
@Override
public class RegisterActivity extends
protected void onCreate(Bundle
AppCompatActivity {
savedInstanceState) {
super.onCreate(savedInstanceState);
@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
TextView loginLink =
findViewById(R.id.login_link);
loginLink.setOnClickListener(new
View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
Button registerButton =
findViewById(R.id.register_button);
registerButton.setOnClickListener(new
View.OnClickListener() {
@Override
public void onClick(View v) {
// Add your registration logic here
}
});
}
}