Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.soft_1.loginthing;
- 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.TextView;
- public class MainActivity extends AppCompatActivity implements View.OnClickListener{
- static String premadeUsername = "Gigi";
- static String premadePassword = "1234567";
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- Button btnLogin = (Button) findViewById(R.id.btn_Login);
- btnLogin.setOnClickListener(this);
- Button btnCancel = (Button) findViewById(R.id.btn_Cancel);
- btnCancel.setOnClickListener(this);
- }
- public void onClick(View v) {
- Button btnLogin = (Button) findViewById(R.id.btn_Login);
- Button btnCancel = (Button) findViewById(R.id.btn_Cancel);
- EditText etPassword = (EditText)findViewById(R.id.etxt_Password);
- EditText etUsername = (EditText)findViewById(R.id.etxt_Username);
- TextView txtError = (TextView)findViewById(R.id.txt_error);
- switch (v.getId()) {
- case R.id.btn_Login:
- if(etPassword.getText().toString().length() < 6)
- {
- txtError.setVisibility(View.VISIBLE);
- txtError.setText("Password cannot be shorter than 6 letters");
- }
- else
- if(etPassword.getText().toString() == premadePassword && etUsername.getText().toString() == premadeUsername )
- {
- txtError.setVisibility(View.VISIBLE);
- txtError.setText("Logged in!");
- }
- else
- {
- txtError.setVisibility(View.VISIBLE);
- txtError.setText("Username or Password is incorrect lol");
- }
- break;
- case R.id.btn_Cancel:
- finish();
- break;
- }
- }
- }
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- tools:context=".MainActivity">
- <TextView
- android:textSize="50dp"
- android:id="@+id/txt_Login"
- android:layout_marginTop="20dp"
- android:layout_centerHorizontal="true"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Login"
- tools:layout_editor_absoluteX="163dp"
- tools:layout_editor_absoluteY="52dp" />
- <TextView
- android:textSize="18dp"
- android:id="@+id/txt_Username"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignBaseline="@+id/etxt_Username"
- android:layout_alignParentStart="true"
- android:layout_marginStart="18dp"
- android:text="Username:"
- tools:layout_editor_absoluteX="59dp"
- tools:layout_editor_absoluteY="169dp" />
- <TextView
- android:textSize="18dp"
- android:id="@+id/txt_Password"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignBaseline="@+id/etxt_Password"
- android:layout_alignStart="@+id/txt_Username"
- android:text="Password:"
- tools:layout_editor_absoluteX="59dp"
- tools:layout_editor_absoluteY="222dp" />
- <EditText
- android:id="@+id/etxt_Username"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentEnd="true"
- android:layout_alignParentTop="true"
- android:layout_marginEnd="48dp"
- android:layout_marginTop="115dp"
- android:ems="10"
- android:inputType="textPersonName"
- android:hint="Username"
- tools:layout_editor_absoluteX="129dp"
- tools:layout_editor_absoluteY="157dp" />
- <Button
- android:id="@+id/btn_Login"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentStart="true"
- android:layout_alignTop="@+id/btn_Cancel"
- android:layout_marginStart="31dp"
- android:text="Login"
- android:textSize="30dp"
- tools:layout_editor_absoluteX="73dp"
- tools:layout_editor_absoluteY="332dp" />
- <Button
- android:id="@+id/btn_Cancel"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentBottom="true"
- android:layout_alignParentEnd="true"
- android:layout_marginBottom="83dp"
- android:layout_marginEnd="31dp"
- android:text="Cancel"
- android:textSize="30dp"
- tools:layout_editor_absoluteX="207dp"
- tools:layout_editor_absoluteY="332dp" />
- <EditText
- android:id="@+id/etxt_Password"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentTop="true"
- android:layout_alignStart="@+id/etxt_Username"
- android:layout_marginTop="211dp"
- android:ems="10"
- android:hint="Password"
- android:inputType="textPassword"
- tools:layout_editor_absoluteX="126dp"
- tools:layout_editor_absoluteY="214dp" />
- <TextView
- android:textSize="30dp"
- android:id="@+id/txt_error"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentBottom="true"
- android:layout_centerHorizontal="true"
- android:layout_marginBottom="187dp"
- android:text="Error"
- android:visibility="invisible"/>
- </RelativeLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement