0% found this document useful (0 votes)
19 views7 pages

Rajajinagar Parent'S Association First Grade College: 70 Cross, Rajajinagar 5 Block, Bangalore - 10

The document describes a mobile application project that includes an activity_main XML layout file defining the user interface and a MainActivity Java class containing code to handle button clicks and display toasts. The layout contains edit texts for username, password, course and register number along with a login button. The activity code gets the values from the edit texts on button click and displays a toast if successful.

Uploaded by

Rohan M
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)
19 views7 pages

Rajajinagar Parent'S Association First Grade College: 70 Cross, Rajajinagar 5 Block, Bangalore - 10

The document describes a mobile application project that includes an activity_main XML layout file defining the user interface and a MainActivity Java class containing code to handle button clicks and display toasts. The layout contains edit texts for username, password, course and register number along with a login button. The activity code gets the values from the edit texts on button click and displays a toast if successful.

Uploaded by

Rohan M
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
You are on page 1/ 7

RAJAJINAGAR PARENT’S ASSOCIATION

FIRST GRADE COLLEGE


70th Cross, Rajajinagar 5th Block, Bangalore – 10

DEPARTMENT OF COMPUTER SCIENCE (BCA)

MOBILE APPLICATION DEVELOPMENT


ASSIGNEMENT – 01

BY:
RAHUL RAO M
(U03JA21S0002)

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">

<EditText
android:id="@+id/editTextRegno"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Register no"
android:inputType="text"
app:layout_constraintBottom_toTopOf="@+id/button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

<EditText
android:id="@+id/editTextCourse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="course"
android:inputType="text"
app:layout_constraintBottom_toTopOf="@+id/editTextRegno"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login to use"
android:textSize="22dp"
app:layout_constraintBottom_toTopOf="@+id/editTextUsername"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<EditText
android:id="@+id/editTextUsername"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="username"
android:inputType="text"
app:layout_constraintBottom_toTopOf="@+id/editTextTextPassword"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

<EditText
android:id="@+id/editTextTextPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="password"
android:inputType="textPassword"
app:layout_constraintBottom_toTopOf="@+id/editTextCourse"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="login"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

MainActivity.java
package com.example.prac;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

EditText editTextUsername, editTextPassword, editTextCourse,


editTextRegisterNumber;
Button buttonLogin;

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

// Initialize EditText and Button


editTextUsername = findViewById(R.id.editTextUsername);
editTextPassword = findViewById(R.id.editTextTextPassword);
editTextCourse = findViewById(R.id.editTextCourse);
editTextRegisterNumber = findViewById(R.id.editTextRegno);
buttonLogin = findViewById(R.id.button);
// Set OnClickListener for the login button
buttonLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Get values from EditText fields
String username = editTextUsername.getText().toString();
String password = editTextPassword.getText().toString();
String course = editTextCourse.getText().toString();
String registerNumber = editTextRegisterNumber.getText().toString();
// Check if any field is empty
if (username.isEmpty() || password.isEmpty() || course.isEmpty() ||
registerNumber.isEmpty()) {
Toast.makeText(MainActivity.this, "Please fill all fields",
Toast.LENGTH_SHORT).show();
} else {
// Display a toast message with the entered details
String message = "Welcome: " + username;
Toast.makeText(MainActivity.this, message,
Toast.LENGTH_SHORT).show();
}
}
});
}
}

You might also like