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

Mad 28

Uploaded by

kamble04ay
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 views3 pages

Mad 28

Uploaded by

kamble04ay
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/ 3

Subject: MAD[22617] Practical no: 28

Performed by: Pratik Bais Roll no: 51

Create a login application where you will have to validate username and password till the username
and password Is not validated,login button remain disabled.

Activity_main.xml

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


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tvName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="21dp"
android:layout_marginTop="49dp"
android:text="User Name"
android:textSize="18sp" />
<EditText
android:id="@+id/etUsername"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/tvName"
android:layout_alignBottom="@+id/tvName"
android:layout_alignParentEnd="true"
android:layout_marginEnd="23dp"
android:ems="10"
android:inputType="textPersonName" />
<TextView
android:id="@+id/tvPass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="@+id/tvName"
android:layout_below="@+id/etUsername"
android:layout_marginTop="32dp"
android:text="Password"
android:textSize="18sp" />
<EditText
android:id="@+id/etPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/tvPass"
android:layout_alignBottom="@+id/tvPass"
android:layout_alignStart="@+id/etUsername"
android:ems="10"
android:inputType="textPassword" />
<Button

1|Page
Subject: MAD[22617] Practical no: 28
Performed by: Pratik Bais Roll no: 51

android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/etPassword"
android:layout_centerHorizontal="true"
android:layout_marginTop="38dp"
android:text="LOGIN"
/>
<TextView
android:id="@+id/tvLoginStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/button"
android:layout_centerHorizontal="true"
android:layout_marginTop="100sp"
/>
</RelativeLayout>

MainActivity.java

package com.example.practicalno28;
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;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
EditText etUsername, etPassword;
Button btnStatus;
TextView tvLoginStatus;
@Override
protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etUsername = (EditText) findViewById(R.id.etUsername);
etPassword = (EditText) findViewById(R.id.etPassword);
btnStatus = (Button) findViewById(R.id.button);
tvLoginStatus = (TextView) findViewById(R.id.tvLoginStatus);
etPassword.addTextChangedListener(TextChange);
etUsername.addTextChangedListener(TextChange);
check();
}
private TextWatcher TextChange=new TextWatcher() {
@Override

2|Page
Subject: MAD[22617] Practical no: 28
Performed by: Pratik Bais Roll no: 51

public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {


}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
check();
}
};
public void check(){
if(etUsername.getText().toString().equals("ABC") && etPassword.getText().toString().equals("1234"))
{
btnStatus.setEnabled(true);
Toast.makeText(getApplicationContext(),"Login Seccessful",Toast.LENGTH_SHORT).show();
}else{
btnStatus.setEnabled(false);
}
}
}

Output:

3|Page

You might also like