Advertisement
Guest User

my first login system

a guest
Aug 15th, 2016
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.91 KB | None | 0 0
  1. MainActivity.java
  2. ======================
  3. package com.example.z.myapplication;
  4.  
  5. import android.app.Activity;
  6. import android.graphics.Color;
  7. import android.support.v7.app.AppCompatActivity;
  8. import android.os.Bundle;
  9. import android.view.View;
  10. import android.widget.EditText;
  11. import android.widget.LinearLayout;
  12. import android.widget.TextView;
  13. import android.widget.Toast;
  14.  
  15. public class MainActivity extends Activity {
  16.  
  17.     EditText txtUserName;
  18.     EditText txtUserPass;
  19.     TextView lblMsg;
  20.     final String MY_USER="zeev";
  21.     final String MY_PASS="12345";
  22.     private int totalTry=5;
  23.  
  24.     @Override
  25.     protected void onCreate(Bundle savedInstanceState) {
  26.         super.onCreate(savedInstanceState);
  27.         setContentView(R.layout.activity_main);
  28.         setPointer();
  29.     }
  30.  
  31.     private void setPointer()
  32.     {
  33.         txtUserName=(EditText)findViewById(R.id.txtUserName);
  34.         txtUserPass=(EditText)findViewById(R.id.txtUserPassword);
  35.         lblMsg=(TextView)findViewById(R.id.lblMsg);
  36.     }
  37.  
  38.     public void btnClick(View view)
  39.     {
  40.         String getUser=txtUserName.getText().toString();
  41.         String getPass=txtUserPass.getText().toString();
  42.  
  43.         if (totalTry==0) {
  44.             Toast.makeText(MainActivity.this, "You are an idiot!!", Toast.LENGTH_SHORT).show();
  45.             return;
  46.         }
  47.  
  48.         if (getUser.equals(MY_USER) && getPass.equals(MY_PASS))
  49.         {
  50.             lblMsg.setText("User loged...");
  51.         }
  52.         else
  53.         {
  54.             totalTry--;
  55.             Toast.makeText(MainActivity.this, "you have "+totalTry+" times", Toast.LENGTH_LONG).show();
  56.  
  57.         }
  58.     }
  59.  
  60. }
  61.  
  62.  
  63. activity_main.xml
  64. =================
  65. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  66.     android:layout_width="match_parent"
  67.     android:layout_height="match_parent"
  68.     android:orientation="vertical">
  69.  
  70.     <LinearLayout
  71.         android:layout_width="match_parent"
  72.         android:layout_height="150dp"
  73.         android:orientation="vertical">
  74.  
  75.         <TextView
  76.             android:layout_width="match_parent"
  77.             android:layout_height="match_parent"
  78.             android:gravity="center"
  79.             android:text="LOGO"
  80.             android:textSize="100sp">
  81.  
  82.         </TextView>
  83.     </LinearLayout>
  84.  
  85.     <LinearLayout
  86.         android:layout_width="match_parent"
  87.         android:layout_height="150dp"
  88.         android:orientation="vertical">
  89.  
  90.         <EditText
  91.             android:id="@+id/txtUserName"
  92.             android:layout_width="match_parent"
  93.             android:layout_height="wrap_content"
  94.             android:hint="Enter your name...."
  95.             android:inputType="text"
  96.             android:textSize="22sp" />
  97.  
  98.         <EditText
  99.             android:id="@+id/txtUserPassword"
  100.             android:layout_width="match_parent"
  101.             android:layout_height="wrap_content"
  102.             android:hint="Enter Password..."
  103.             android:inputType="textPassword"
  104.             android:textSize="22sp" />
  105.     </LinearLayout>
  106.  
  107.     <LinearLayout
  108.         android:layout_width="match_parent"
  109.         android:layout_height="70dp"
  110.         android:orientation="vertical">
  111.  
  112.         <Button
  113.             android:layout_width="match_parent"
  114.             android:layout_height="wrap_content"
  115.             android:text="Login"
  116.             android:background="#91E0FF"
  117.             android:textColor="#ffffff"
  118.             android:textSize="32sp"
  119.             android:onClick="btnClick"/>
  120.     </LinearLayout>
  121.  
  122.     <LinearLayout
  123.         android:layout_width="match_parent"
  124.         android:layout_height="match_parent"
  125.         android:orientation="vertical">
  126.     <TextView
  127.         android:layout_width="match_parent"
  128.         android:layout_height="match_parent"
  129.         android:textSize="32sp"
  130.         android:text="MY LOGIN SYSTEM V1"
  131.         android:gravity="center"
  132.         android:id="@+id/lblMsg"/>
  133.     </LinearLayout>
  134. </LinearLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement