Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MainActivity.java
- ======================
- package com.example.z.myapplication;
- import android.app.Activity;
- import android.graphics.Color;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.EditText;
- import android.widget.LinearLayout;
- import android.widget.TextView;
- import android.widget.Toast;
- public class MainActivity extends Activity {
- EditText txtUserName;
- EditText txtUserPass;
- TextView lblMsg;
- final String MY_USER="zeev";
- final String MY_PASS="12345";
- private int totalTry=5;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- setPointer();
- }
- private void setPointer()
- {
- txtUserName=(EditText)findViewById(R.id.txtUserName);
- txtUserPass=(EditText)findViewById(R.id.txtUserPassword);
- lblMsg=(TextView)findViewById(R.id.lblMsg);
- }
- public void btnClick(View view)
- {
- String getUser=txtUserName.getText().toString();
- String getPass=txtUserPass.getText().toString();
- if (totalTry==0) {
- Toast.makeText(MainActivity.this, "You are an idiot!!", Toast.LENGTH_SHORT).show();
- return;
- }
- if (getUser.equals(MY_USER) && getPass.equals(MY_PASS))
- {
- lblMsg.setText("User loged...");
- }
- else
- {
- totalTry--;
- Toast.makeText(MainActivity.this, "you have "+totalTry+" times", Toast.LENGTH_LONG).show();
- }
- }
- }
- activity_main.xml
- =================
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical">
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="150dp"
- android:orientation="vertical">
- <TextView
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:gravity="center"
- android:text="LOGO"
- android:textSize="100sp">
- </TextView>
- </LinearLayout>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="150dp"
- android:orientation="vertical">
- <EditText
- android:id="@+id/txtUserName"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:hint="Enter your name...."
- android:inputType="text"
- android:textSize="22sp" />
- <EditText
- android:id="@+id/txtUserPassword"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:hint="Enter Password..."
- android:inputType="textPassword"
- android:textSize="22sp" />
- </LinearLayout>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="70dp"
- android:orientation="vertical">
- <Button
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="Login"
- android:background="#91E0FF"
- android:textColor="#ffffff"
- android:textSize="32sp"
- android:onClick="btnClick"/>
- </LinearLayout>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical">
- <TextView
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:textSize="32sp"
- android:text="MY LOGIN SYSTEM V1"
- android:gravity="center"
- android:id="@+id/lblMsg"/>
- </LinearLayout>
- </LinearLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement