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

Practical No 28

The document describes an Android login screen layout and code. It includes the XML layout file activity_main.xml which defines the user interface containing an EditText for username, EditText for password, a login button, and text views. The MainActivity.java file contains the code behind for handling text changes in the username and password fields, enabling/disabling the login button based on valid input, and tracking the number of login attempts. On valid username and password, the login button is enabled, otherwise it remains disabled. The number of remaining attempts is displayed in a text view and decremented each time the submit button is clicked.

Uploaded by

atharvabutte03
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)
228 views2 pages

Practical No 28

The document describes an Android login screen layout and code. It includes the XML layout file activity_main.xml which defines the user interface containing an EditText for username, EditText for password, a login button, and text views. The MainActivity.java file contains the code behind for handling text changes in the username and password fields, enabling/disabling the login button based on valid input, and tracking the number of login attempts. On valid username and password, the login button is enabled, otherwise it remains disabled. The number of remaining attempts is displayed in a text view and decremented each time the submit button is clicked.

Uploaded by

atharvabutte03
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/ 2

Practical No 28

Q1.
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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<EditText
android:id="@+id/editTextTextPersonName"
android:layout_width="162dp"
android:layout_height="48dp"
android:ems="10"
android:inputType="textPersonName"
android:text="Atharva Butte"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

<LinearLayout
android:layout_width="414dp"
android:layout_height="657dp"
android:layout_marginTop="36dp"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.666"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Login"
android:textSize="34sp" />

<ImageView
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="40dp"
android:src="@drawable/img"/>

<Space
android:layout_width="match_parent"
android:layout_height="70dp" />

<EditText
android:id="@+id/unm"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:hint="Enter username"
android:inputType="text" />

<EditText
android:id="@+id/pass"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:hint="Enter password"
android:inputType="text" />

<TextView
android:id="@+id/atmt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginTop="10dp"
android:textColor="#FF0000"
android:textSize="20sp" />

<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginTop="20dp"
android:layout_marginRight="60dp"
android:onClick="submit"
android:text="Login" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

MainActivity.java
package com.example.practical26;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.*;

public class MainActivity extends AppCompatActivity {


private int attempt = 3;
private boolean valid_unm = false, valid_pass = false;
EditText unm , pass;
Button btn;
TextView atmt;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
unm = findViewById(R.id.unm);
pass = findViewById(R.id.pass);
atmt = findViewById(R.id.atmt);
atmt.setText("Remaing Attempt: "+attempt);
btn = findViewById(R.id.btn);
btn.setEnabled(false);

unm.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int
after) { }
@Override
public void onTextChanged(CharSequence s, int start, int before, int count)
{
String txt = s.toString();
valid_unm = (!txt.equals("")) ? true : false;
if (valid_unm && valid_pass)
btn.setEnabled(true);
}
@Override
public void afterTextChanged(Editable s) { }
});

pass.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int
after) { }

You might also like