SHARE
TWEET

Untitled

a guest May 20th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. login.java
  2.  
  3. package com.android;
  4.  
  5. import android.app.Activity;
  6. import android.content.Intent;
  7. import android.os.Bundle;
  8. import android.view.View;
  9. import android.widget.Button;
  10. import android.widget.EditText;
  11. import android.widget.Toast;
  12.  
  13. public class login extends Activity {
  14.     Button btn1,btn2;
  15.     EditText et1,et2;
  16.     private int counter = 5;
  17.     /** Called when the activity is first created. */
  18.     @Override
  19.     public void onCreate(Bundle savedInstanceState) {
  20.         super.onCreate(savedInstanceState);
  21.         setContentView(R.layout.login);
  22.         et1=(EditText)findViewById(R.id.et1);
  23.         et2=(EditText)findViewById(R.id.et2);
  24.         btn1=(Button)findViewById(R.id.btn1);
  25.         btn2=(Button)findViewById(R.id.btn2);
  26.        
  27.         btn1.setOnClickListener(new View.OnClickListener() {
  28.            
  29.             public void onClick(View v) {
  30.                 // TODO Auto-generated method stub
  31.                 validate(et1.getText().toString(), et2.getText().toString());
  32.                
  33.             }
  34.         });
  35.     }
  36.    
  37.     public void btnClickCancel(View v){
  38.         Intent i = new Intent(this,StudentInformationSystem.class);
  39.         startActivity(i);
  40.        
  41.     }
  42.     public void validate(String userName, String userPassword){
  43.         if((userName.equals("Philip")) && (userPassword.equals("Pretila"))){
  44.         Toast.makeText(getApplicationContext(), "login success", Toast.LENGTH_SHORT).show();
  45.         }
  46.         else{
  47.             counter--;
  48.             Toast.makeText(getApplicationContext(), "Wrong Credentials", Toast.LENGTH_LONG).show();
  49.             if(counter == 0){
  50.             btn1.setEnabled(false);
  51.             }
  52.         }
  53.            
  54.            
  55.     }
  56.    
  57.    
  58. }
  59.  
  60.  
  61.  
  62.  
  63. login xml
  64.  
  65.  
  66. <?xml version="1.0" encoding="utf-8"?>
  67. <LinearLayout
  68.   xmlns:android="http://schemas.android.com/apk/res/android"
  69.   android:layout_width="match_parent"
  70.   android:layout_height="match_parent" android:baselineAligned="false">
  71.     <RelativeLayout android:layout_height="match_parent" android:id="@+id/relativeLayout1" android:layout_width="320dip">
  72.         <EditText
  73.         android:layout_alignParentLeft="true"
  74.         android:id="@+id/et1"
  75.         android:layout_height="wrap_content"
  76.         android:hint="Username"
  77.         android:layout_width="320dip" android:layout_marginTop="20dip">
  78.         </EditText>
  79.         <EditText  
  80.         android:id="@+id/et2"
  81.         android:layout_below="@+id/et1"
  82.         android:layout_height="wrap_content"
  83.         android:inputType="textPassword"
  84.         android:hint="Password"
  85.         android:layout_width="320dip">
  86.         </EditText>
  87.         <Button
  88.         android:id="@+id/btn1"
  89.         android:layout_below="@+id/et2"
  90.         android:text="OK"
  91.         android:layout_height="wrap_content"
  92.         android:layout_width="150dip"
  93.         android:layout_marginLeft="80dip"
  94.         android:layout_marginTop="40dip">
  95.         </Button>
  96.         <Button
  97.         android:id="@+id/btn2"
  98.         android:layout_below="@+id/btn1"
  99.         android:text="Cancel"  
  100.         android:layout_height="wrap_content"
  101.         android:layout_width="150dip"
  102.         android:onClick="btnClickCancel"
  103.         android:layout_marginLeft="80dip">
  104.         </Button>
  105.     </RelativeLayout>
  106. </LinearLayout>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top