0% found this document useful (0 votes)
32 views4 pages

Prac 28

Uploaded by

Miran Jamadar
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)
32 views4 pages

Prac 28

Uploaded by

Miran Jamadar
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/ 4

<?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">

<TextView
android:id="@+id/tv0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="LOGIN FORM "
android:textColor="@color/black"
android:textSize="40dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.041" />

<TextView
android:id="@+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:layout_marginRight="40dp"
android:text="USERNAME"
android:textColor="@color/black"
android:textSize="30dp"
app:layout_constraintHorizontal_bias="0.075"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv0" />

<TextView

android:id="@+id/tv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:layout_marginRight="40dp"
android:text="PASSWORD"
android:textColor="@color/black"
android:textSize="30dp"
app:layout_constraintHorizontal_bias="0.075"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv1" />

<EditText
android:id="@+id/edu"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="16dp"
android:hint="USERNAME"
android:textSize="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toRightOf="@id/tv1"
app:layout_constraintTop_toBottomOf="@id/tv0" />

<EditText
android:id="@+id/edp"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="48dp"
android:layout_marginEnd="16dp"
android:textSize="20dp"
android:hint="PASSWORD"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toRightOf="@id/tv2"
app:layout_constraintTop_toBottomOf="@id/edu" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/bus"
app:layout_constraintTop_toBottomOf="@id/edp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:text="LOGIN"
android:enabled="false"

android:layout_marginTop="50dp"/>
</androidx.constraintlayout.widget.ConstraintLayout>

package com.example.lpogon;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {


EditText e1, e2;
Button b;

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

e1 = findViewById(R.id.edu);
e2 = findViewById(R.id.edp);
b = findViewById(R.id.bus);

e1.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) {
checkCredentials();
}

@Override
public void afterTextChanged(Editable s) {
}
});

e2.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) {
checkCredentials();
}

@Override
public void afterTextChanged(Editable s) {
}
});
}

private void checkCredentials() {


if (e1.getText().toString().equals("admin") && e2.getText().toString().equals("admin123")) {
b.setEnabled(true);
} else {
b.setEnabled(false);
}
}
}

You might also like