TechSupportNepTechSupportNep - Programming & Tech

  • Home
  • C#.NET
  • PHP
  • JAVA
  • Python
  • ASP.NET
  • VB.NET
  • Android
  • C
  • Tech
    • Tech News
  • Patreoner
TechSupportNep
  • Home
  • Programming
  • Android
  • How to Create Simple Login Form in Android Studio Without using Database?
Android

How to Create Simple Login Form in Android Studio Without using Database?

By Er. Ran Bahadur B.K. Last updated Aug 15, 2021
0 4,062
Share

if you guyz are just the beginners in android programming and you don’t know how to work with android studio and how to design the forms in android and also how to define, initialize variables in android studio then this tutorial is for you guyz.

Let’s start.

STEPS:

1. First of all you need to have android studio in your computer, if not download and install it from here: CLICK HERE and then goto Tools>Andorid>SDK Manager and install all SDK Platforms and SDK Tools and then click shift+f10 new window will appear after then click on create new virtual device and then select phone from the left pane and then choose any name you want like nexus 5 and then click next choose any android version in the next window and the click next and then click finish; this will create the virtual device in your android studio so that you can run your apps or you can run the apps in your android phone too. For this you need to install the phone specific driver in your PC, and then go to the setting of your phone and enable usb debugging mode, and then connect your phone with PC through the help of USB cable then you will be able to run app in your phone. Or you can install third party AVD in your Computer to run your apps like genymotion. i explain the process of running the apps because in other programming langue you do not to take any thing simply click on the play button and your program will start to execute but in android studio we are create apps for mobile devices so we need mobile device to run the apps or virtual mobile device to run it. i think you may understand this.

2. Open Android Studio, go to file>new>new project; give application name click next, select phone and tablets;click next, select empty activity click next and finally click finish.

Now you project will open in android studio. Go to res>layout>activity_main.xml. Double click on activity_mail.xml file, select design section. And drag and drop two edittext and one button and change their properties as shown in the video. OR simply copy following code; keep in mind that you need to change the package name and application name.

Designing code:


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="ran.com.loginformsimple.MainActivity">

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:layout_marginTop="23dp"
android:id="@+id/txtuser"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:hint="Username"
android:textSize="20sp" />

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:layout_marginTop="22dp"
android:id="@+id/txtpass"
android:hint="Password"
android:textSize="20sp"
android:layout_below="@+id/txtuser"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

<Button
android:text="Login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:id="@+id/btnlogin"
android:textSize="20sp"
android:layout_below="@+id/txtpass"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>

3. Now goto java>yourpackagename.com.applicationname in my case java>ran.com.loginformsimple>MainActivity

a. Inside the class declare the following variable as:

Button login;
EditText username, password;

b. Inside the onCreate method initialize each control as:

login=(Button)findViewById(R.id.btnlogin);
username=(EditText)findViewById(R.id.txtuser);
password=(EditText)findViewById(R.id.txtpass);

c. Now you have two option: either you can write the following piece of code just by creating the listening event of button or you can create one method inside the class but outside the onCreate method and call this method inside the listening event of the button.

So, i am gonna use the second one. but if you want to use the first method, you only need to create the listening event of the button and the copy the following code removing the method i.e. exclude public void login(){}

d. Create one method and write the following code inside that method:

  public void login(){
    String user=username.getText().toString().trim();
    String pass=password.getText().toString().trim();
    if(user.equals("techsupportnep")&& pass.equals("techsupportnep"))
    {
        Toast.makeText(this,"username and password matched!",Toast.LENGTH_LONG).show();
    }else {
        Toast.makeText(this,"username and password do not matched!",Toast.LENGTH_LONG).show();
    }
}

e. Now go inside the onCreate method and create the listening event of button and call this method as just below the initialization of editText and Button:

login.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        login();

    }
});

f. Press shift+f10 or simply click in the play button below the menu of the android studio and t

hen select your AVD either builtin AVD , or third party AVD or your phone device and then click proceed.

That’s it if you have any confusion you can watch the following video:

 

Continue Reading
android app loginandroid app login screenandroid app login screen designandroid code for loginandroid developer loginandroid form designandroid login activityandroid login designandroid login form codeandroid login layoutandroid login ui designandroid studio login activityconfigurating avd in android studiocreate login from in android programmaticallylogin android studiologin code for androidlogin code in androidlogin form designsimple login form in androidstudio code login
0 4,062
Share FacebookTwitterReddItWhatsAppPinterestEmail
Er. Ran Bahadur B.K.60 posts 56 comments

Ran Bahadur B.K. is the owner of TechSupportNep who is working with the aim of providing the quality Technology content. He is creating Tech and Programming videos, you can see all them in his YouTube Channel(https://www.youtube.com/TechSupportNep). He is also working with some company.

Prev Post

Create Simple Login Form in C#.NET Without Connecting to Database [With Source Code]

Next Post

How to Send Free SMS Using C#.NET? [With Source Code]

Leave a comment
Help Needed

This website is free of annoying ads. We want to keep it like this. You can help with your support:

Donate!

The need for Support! Why to Support?

If you need your own website? contact me!
erranbahadurbk
Fiverr
Seller
Hello there,This is me Ran Bahadur B.K., A graduated computer engineer. I have 3+ years of work experience in wordpress design and development. I have strong knowledge of HTML, CSS and PHP which are the three ingredients of web development. Currently i am working with the software company so i also have experience in desktop apps and mobile apps development.

Latest

Python

How to Create Login Application in Python using SQLite Database?

How to use View Binding in Android?

Windows 10 Build 1909 Features that you should know.

How to Create a Complete Login and Forgot Password System in java ?

Prev Next 1 of 15
  • About us
  • Contact us
  • Privacy Policy
  • Disclaimer
© 2023 All Rights Reserved.
Website By: Ran Bahadur B.K.