Advertisement
JanBarhoum

TASK (android studio log in page )

Dec 20th, 2017
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.13 KB | None | 0 0
  1. main activity xml :
  2. <?xml version="1.0" encoding="utf-8"?>
  3. <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4.     xmlns:app="http://schemas.android.com/apk/res-auto"
  5.     xmlns:tools="http://schemas.android.com/tools"
  6.     android:layout_width="match_parent"
  7.     android:layout_height="match_parent"
  8.     tools:context="com.example.jan25.mytask3.MainActivity">
  9.  
  10.     <LinearLayout
  11.         android:layout_width="376dp"
  12.         android:layout_height="30dp"
  13.         android:orientation="vertical"
  14.         tools:layout_editor_absoluteX="8dp"
  15.         tools:layout_editor_absoluteY="8dp">
  16.  
  17.         <TextView
  18.             android:id="@+id/logPage"
  19.             android:layout_width="match_parent"
  20.             android:layout_height="wrap_content"
  21.             android:gravity="center"
  22.             android:text="LogIn Page" />
  23.  
  24.     </LinearLayout>
  25.  
  26.     <LinearLayout
  27.         android:layout_width="373dp"
  28.         android:layout_height="142dp"
  29.         android:orientation="vertical"
  30.         tools:layout_editor_absoluteX="6dp"
  31.         tools:layout_editor_absoluteY="122dp">
  32.  
  33.         <EditText
  34.             android:id="@+id/usertxt"
  35.             android:layout_width="match_parent"
  36.             android:layout_height="wrap_content"
  37.             android:ems="10"
  38.             android:inputType="textPersonName"
  39.             android:text="@string/userName" />
  40.  
  41.         <EditText
  42.             android:id="@+id/passtxt"
  43.             android:layout_width="match_parent"
  44.             android:layout_height="wrap_content"
  45.             android:ems="10"
  46.             android:inputType="textPersonName"
  47.             android:text="@string/userPass" />
  48.  
  49.         <Button
  50.             android:id="@+id/btnsign"
  51.             android:layout_width="match_parent"
  52.             android:layout_height="wrap_content"
  53.             android:onClick="onClick"
  54.             android:text="@string/button"
  55.             tools:text="Sign In" />
  56.  
  57.     </LinearLayout>
  58. </android.support.constraint.ConstraintLayout>
  59. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  60.  
  61. main activity java
  62.  
  63. package com.example.jan25.mytask3;
  64.  
  65. import android.support.v7.app.AppCompatActivity;
  66. import android.os.Bundle;
  67. import android.view.View;
  68. import android.widget.EditText;
  69. import android.widget.Toast;
  70.  
  71. public class MainActivity extends AppCompatActivity implements View.OnClickListener {
  72.     final String USERNAME_DB = "Jan", USERPASS_DB = "123";
  73.     EditText usertxt, passtxt;
  74.  
  75.     @Override
  76.     protected void onCreate(Bundle savedInstanceState) {
  77.         super.onCreate(savedInstanceState);
  78.         setContentView(R.layout.activity_main);
  79.         setPointer();
  80.  
  81.  
  82.     }
  83.  
  84.     public void setPointer() {
  85.         usertxt = findViewById(R.id.usertxt);
  86.         passtxt = findViewById(R.id.passtxt);
  87.     }
  88.  
  89.     @Override
  90.     public void onClick(View view) {
  91.         String userName = usertxt.getText().toString();
  92.         String userPass = passtxt.getText().toString();
  93.  
  94.         switch (view.getId()) {
  95.             case R.id.btnsign:
  96.                 if (userName.equals(USERNAME_DB)) {
  97.                     if (userPass.equals(USERPASS_DB))
  98.                         Toast.makeText(MainActivity.this, getString(R.string.loginSuccess), Toast.LENGTH_SHORT).show();
  99.  
  100.  
  101.                     }
  102.                     else {
  103.                 Toast.makeText(MainActivity.this, getString(R.string.loginErrorUserNull), Toast.LENGTH_SHORT).show();
  104.  
  105.                 }
  106.         }
  107.     }
  108. }
  109. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  110.  
  111. strings
  112.  
  113. <resources>
  114.     <string name="app_name">myTask3</string>
  115.     <string name="userName">Enter Username </string>
  116.     <string name="userPass">Enter Password </string>
  117.     <string name="button">Sign In </string>
  118.     <string name="loginSuccess">Login successful</string>
  119.     <string name="loginErrorUserNull">Invalid username or password</string>
  120.  
  121.  
  122. </resources>
  123. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement