Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Register.java
- ====================
- package com.example.zeevm.mysharedpref;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- public class Register extends AppCompatActivity {
- Button btnCancel;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_register);
- setPointer();
- }
- private void setPointer()
- {
- btnCancel=(Button)findViewById(R.id.btnCancel);
- btnCancel.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- finish();
- }
- });
- }
- }
- activity_register.xml
- ==============================
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical">
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginTop="20dp"
- android:gravity="center"
- android:text="USER REGISTERTION"
- android:textSize="32sp" />
- <RelativeLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <EditText
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:hint="Enter User Name...."
- android:id="@+id/txtUserName"/>
- <EditText
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:hint="Enter password...."
- android:id="@+id/txtPassword"
- android:layout_below="@id/txtUserName"/>
- <EditText
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:hint="Enter password again..."
- android:id="@+id/txtPassword2"
- android:layout_below="@id/txtPassword"/>
- <Button
- android:layout_width="150dp"
- android:layout_height="wrap_content"
- android:id="@+id/btnRegisterUser"
- android:layout_below="@id/txtPassword2"
- android:text="Register"/>
- <Button
- android:layout_width="150dp"
- android:layout_height="wrap_content"
- android:text="Cancel"
- android:id="@+id/btnCancel"
- android:layout_toEndOf="@id/btnRegisterUser"
- android:layout_below="@id/txtPassword2"/>
- </RelativeLayout>
- </LinearLayout>
- MainActivity.java
- =====================
- package com.example.zeevm.mysharedpref;
- import android.content.Intent;
- 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;
- import android.widget.Toast;
- public class MainActivity extends AppCompatActivity {
- EditText txtUserName;
- EditText txtUserPass;
- TextView lblMsg;
- final String MY_USER="zeev";
- final String MY_PASS="12345";
- private int totalTry=5;
- Button btnLogin;
- Button btnRegister;
- @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);
- btnLogin=(Button)findViewById(R.id.btnLogin);
- btnRegister=(Button)findViewById(R.id.btnRegister);
- //listerners
- btnLogin.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- login();
- }
- });
- btnRegister.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- register();
- }
- });
- }
- private void login()
- {
- 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();
- }
- }
- private void register()
- {
- startActivity(new Intent(this,Register.class));
- }
- }
- 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="100dp"
- 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="150dp"
- android:orientation="vertical">
- <Button
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="Login"
- android:background="#00BFFF"
- android:textColor="#ffffff"
- android:textSize="32sp"
- android:id="@+id/btnLogin"
- android:layout_marginBottom="20dp"/>
- <Button
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="Register"
- android:background="#00BFFF"
- android:textColor="#ffffff"
- android:textSize="32sp"
- android:id="@+id/btnRegister"/>
- </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