9 LOGIN SCREEN



 AIM: Create an android program for the login screen, when sign in button is clicked, it validates the user and displays whether is using valid or invalid thru toast message.

Algorithm:
Step 1) Create a new Android Studio Project named as loginscreen.

Step 2)Goto Project Structure and open activity_main.xml file

Step 3) Create two EditText boxes and Button in Activity_main.xml file or drag and drop from the
palette.

Step 4) Add EditText and Button constraints to left, right, top and bottom of the parent view.
Step 5) Add android:onClick=” login” attribute to Button in the activity_main.xml file.
Implement the show method created in MainActivity.java file.

public void login(View view) {
}


Step 6) Create default username and password for Login validation check whether the user entered username and password are match with default username and password display Toast Message as
Valid User otherwise Invalid User.

Step 6) Run the application from the menu bar select Run and Click on Run App option.


Program:

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity">




-




<EditText android:id="@+id/editText1"
android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginEnd="84dp" android:layout_marginStart="85dp" android:layout_marginTop="64dp" android:ems="10" android:inputType="textPersonName" android:hint="Enter First Number" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" />

<EditText android:id="@+id/editText2"
android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginEnd="84dp" android:layout_marginStart="85dp" android:layout_marginTop="64dp" android:ems="10" android:inputType="textPersonName" android:hint="Enter Second Number" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editText" />

<Button android:id="@+id/button"
android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="180dp" android:layout_marginEnd="148dp" android:layout_marginStart="148dp" android:layout_marginTop="63dp" android:text="Login" android:onClick="loginCheck" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/editText2" />
</android.support.constraint.ConstraintLayout>

MainActivity.java:

package com.example.loginscreen;

import android.support.v7.app.AppCompatActivity; import android.os.Bundle;
import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast;
public class MainActivity extends AppCompatActivity { EditText editText1,editText2;
Button button;
String username="admin"; String password="root";

@Override
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
}
public void loginCheck(View view) { editText1=(EditText)findViewById(R.id.editText1); editText2=(EditText)findViewById(R.id.editText2); String value1=editText1.getText().toString(); String value2=editText2.getText().toString();
if(value1.equalsIgnoreCase(username) && value2.equalsIgnoreCase(password))
{
Toast.makeText(getApplicationContext(),"Valid User",Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(getApplicationContext(),"In alid User",Toast.LENGTH_SHORT).show();
}

}

}
OUTPUT:

Comments

Popular posts from this blog

20 Simple Content Provider Example

14 Popup Menu

19 SQLIte SImple Database Example