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

Practical 7.1

The document contains an XML layout file for an Android login interface, including fields for username and password, and a login button. It also includes a Java class that handles user input, validates the fields, and displays a success message upon successful login. The layout and functionality are designed for a simple user authentication process in an Android application.

Uploaded by

Pruthesh Upadhye
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)
9 views3 pages

Practical 7.1

The document contains an XML layout file for an Android login interface, including fields for username and password, and a login button. It also includes a Java class that handles user input, validates the fields, and displays a success message upon successful login. The layout and functionality are designed for a simple user authentication process in an Android application.

Uploaded by

Pruthesh Upadhye
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

7.1 activity_main.

xml

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Username"
android:textSize="18sp"/>

<EditText
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Username"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password"
android:textSize="18sp"
android:layout_marginTop="10dp"/>

<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Password"
android:inputType="textPassword"/>

<Button
android:id="@+id/loginButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login"
android:layout_marginTop="20dp"/>

<TextView
android:id="@+id/resultText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textSize="18sp"
android:textColor="@android:color/holo_red_dark"
android:layout_marginTop="10dp"/>
</LinearLayout>
7.1 MainActivity.java

package com.example.practical7;

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

public class MainActivity extends AppCompatActivity {

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

EditText usernameInput = findViewById(R.id.username);


EditText passwordInput = findViewById(R.id.password);
Button loginButton = findViewById(R.id.loginButton);
TextView resultText = findViewById(R.id.resultText);

loginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String username = usernameInput.getText().toString().trim();
String password = passwordInput.getText().toString().trim();

if (username.isEmpty() || password.isEmpty()) {
resultText.setText("Please enter both username and
password.");
} else {
resultText.setText("Login Successful! Welcome, " +
username);
}
}
});
}
}
7.1 Output

You might also like