Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MAinActivity
- package com.example.z.myapplication;
- import android.app.Activity;
- import android.content.Intent;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.EditText;
- 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";
- final String USER="Zeev Mindely";
- 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...");
- Intent myInt = new Intent(this,Main2Activity.class);
- myInt.putExtra("Main2Activity",this.USER);
- startActivity(myInt);
- finish();
- }
- else
- {
- totalTry--;
- Toast.makeText(MainActivity.this, "you have "+totalTry+" times", Toast.LENGTH_LONG).show();
- }
- }
- }
- activity Main
- <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>
- MAin2Activity
- package com.example.z.myapplication;
- import android.content.Intent;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.widget.TextView;
- public class Main2Activity extends MainActivity {
- TextView myText;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main2);
- setPointer();
- myText.setText(getIntent().getStringExtra("Main2Activity"));
- }
- public void setPointer(){
- myText=(TextView)findViewById(R.id.USER);
- }
- }
- activity main 2
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:paddingBottom="@dimen/activity_vertical_margin"
- android:paddingLeft="@dimen/activity_horizontal_margin"
- android:paddingRight="@dimen/activity_horizontal_margin"
- android:paddingTop="@dimen/activity_vertical_margin"
- tools:context="com.example.z.myapplication.Main2Activity">
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- >
- <TextView
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:gravity="center"
- android:layout_margin="12dp"
- android:textSize="36dp"
- android:id="@+id/USER"/>
- </LinearLayout>
- </RelativeLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement