0% found this document useful (0 votes)
40 views2 pages

JAVA CODE-WPS Office

This Java code defines a MainActivity class for an Android application that manages user login and registration. It includes UI elements for inputting credentials and buttons to toggle between login and registration tabs. The code also contains mock functionality to validate login credentials and register users with toast notifications for feedback.

Uploaded by

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

JAVA CODE-WPS Office

This Java code defines a MainActivity class for an Android application that manages user login and registration. It includes UI elements for inputting credentials and buttons to toggle between login and registration tabs. The code also contains mock functionality to validate login credentials and register users with toast notifications for feedback.

Uploaded by

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

JAVA CODE:

package com.example.traindelivery;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

LinearLayout layoutLogin, layoutRegister;


Button btnLoginTab, btnRegisterTab, btnLogin, btnRegister;
EditText etLoginEmail, etLoginPassword, etRegisterName, etRegisterEmail,
etRegisterPassword;

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

// Tabs
btnLoginTab = findViewById(R.id.btnLoginTab);
btnRegisterTab = findViewById(R.id.btnRegisterTab);

// Layouts
layoutLogin = findViewById(R.id.layoutLogin);
layoutRegister = findViewById(R.id.layoutRegister);

// Login
etLoginEmail = findViewById(R.id.etLoginEmail);
etLoginPassword = findViewById(R.id.etLoginPassword);
btnLogin = findViewById(R.id.btnLogin);

// Register
etRegisterName = findViewById(R.id.etRegisterName);
etRegisterEmail = findViewById(R.id.etRegisterEmail);
etRegisterPassword = findViewById(R.id.etRegisterPassword);
btnRegister = findViewById(R.id.btnRegister);

// Toggle tabs
btnLoginTab.setOnClickListener(v -> {
layoutLogin.setVisibility(View.VISIBLE);
layoutRegister.setVisibility(View.GONE);
});

btnRegisterTab.setOnClickListener(v -> {
layoutRegister.setVisibility(View.VISIBLE);
layoutLogin.setVisibility(View.GONE);
});

// Login button action


btnLogin.setOnClickListener(v -> {
String email = etLoginEmail.getText().toString();
String pass = etLoginPassword.getText().toString();
// Here you'd check credentials (mocked)
if (email.equals("[email protected]") && pass.equals("1234")) {
Toast.makeText(this, "Login Success", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "Invalid Credentials",
Toast.LENGTH_SHORT).show();
}
});

// Register button action


btnRegister.setOnClickListener(v -> {
String name = etRegisterName.getText().toString();
String email = etRegisterEmail.getText().toString();
String pass = etRegisterPassword.getText().toString();
// Mock register (you'd save data here)
Toast.makeText(this, "Registered Successfully",
Toast.LENGTH_SHORT).show();
});
}
}

You might also like