Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

MAD Practical 28

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Name: Pratham android:id="@+id/edt1"

Roll No: 3
android:layout_width="match_parent"
Q28)
activity_main.xml
android:layout_height="wrap_content"
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_below="@id/textView"
xmlns:android="http://schemas.android.c
om/apk/res/android" android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
xmlns:tools="http://schemas.android.com
android:layout_marginTop="50dp"
/tools"
android:background="#ECECEC"
android:layout_width="match_parent"
android:ems="10"
android:layout_height="match_parent"
android:hint="Username"
tools:context=".MainActivity">

android:inputType="textPersonName"
<TextView
android:padding="12dp" />
android:id="@+id/textView"

<EditText
android:layout_width="wrap_content"
android:id="@+id/edt2"

android:layout_height="wrap_content"
android:layout_width="match_parent"

android:layout_centerHorizontal="true"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:layout_below="@id/edt1"
android:fontFamily="sans-serif-
condensed-light" android:layout_marginStart="20dp"

android:text="LOGIN" android:layout_marginEnd="20dp"

android:textColor="#273898" android:layout_marginTop="20dp"

android:textSize="30sp" android:background="#ECECEC"

android:textStyle="bold" /> android:ems="10"


android:hint="Password"

<EditText android:inputType="textPassword"
android:padding="12dp" /> </RelativeLayout>
MainActivity.java
<Button package com.example.practicaal;
android:id="@+id/button"
android:layout_width="140dp" import
androidx.appcompat.app.AppCompatActiv
android:layout_height="wrap_content" ity;

android:layout_below="@id/edt2"
import android.os.Bundle;
android:layout_centerHorizontal="true" import android.view.View;
android:layout_marginTop="30dp" import android.widget.Button;
android:backgroundTint="#03A9F4" import android.widget.EditText;
android:onClick="formLogin" import android.widget.TextView;
android:text="Login" import android.widget.Toast;
android:textColor="#FFFFFF"
android:textSize="16sp" public class MainActivity extends
AppCompatActivity {
android:textStyle="bold" />

EditText ed1,
<TextView
ed2; TextView tv;
android:id="@+id/textView2"
Button b1;
android:layout_width="wrap_content" int count;

android:layout_height="wrap_content"
@Override
android:layout_below="@id/button"
protected void
onCreate(Bundle
android:layout_centerHorizontal="true" savedInstanceState) {
android:layout_marginTop="30dp" super.onCreate(savedInstanceState);
android:textColor="#000000"
android:textSize="20sp" /> setContentView(R.layout.activity_main);

ed1 = findViewById(R.id.edt1);
ed2 = findViewById(R.id.edt2); tv.setText("");
tv = findViewById(R.id.textView2); }
b1 = findViewById(R.id.button); }
}
count = 3; Output:
tv.setText("You have only " + count +
" Attempts");
}

public void formLogin(View view)


{ String uname, passwd;
uname = ed1.getText().toString();
passwd =
ed2.getText().toString(); count--;
tv.setText("Attempts left: " +
count); if (count == 0) {
b1.setEnabled(false);
}
if (uname.equals("") &&
passwd.equals("")) {
Toast.makeText(MainActivity.this,
"Please enter username and
password",
Toast.LENGTH_SHORT).show();
} else if (passwd.length() < 8) {
Toast.makeText(MainActivity.this,
"Password should be 8 characters
long", Toast.LENGTH_SHORT).show();
} else if (uname.equals("Admin") &&
passwd.equals("12345678")) {
Toast.makeText(MainActivity.this,
"Login successful",
Toast.LENGTH_SHORT).show();

You might also like