Guest User

app

a guest
Dec 10th, 2017
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.69 KB | None | 0 0
  1. package com.example.dell.login;
  2.  
  3. import android.content.Intent;
  4. import android.support.v7.app.AppCompatActivity;
  5. import android.os.Bundle;
  6. import android.view.View;
  7. import android.widget.AdapterView;
  8. import android.widget.Button;
  9. import android.widget.EditText;
  10. import android.widget.TextView;
  11.  
  12. import java.net.PasswordAuthentication;
  13.  
  14. public class MainActivity extends AppCompatActivity{
  15.  
  16.     private EditText Name;
  17.     private EditText Password;
  18.     private TextView Info;
  19.     private Button Login;
  20.     private int counter=5;
  21.  
  22.     @Override
  23.     protected void onCreate(Bundle savedInstanceState) {
  24.         super.onCreate(savedInstanceState);
  25.         setContentView(R.layout.activity_main);
  26.  
  27.         Name = (EditText) findViewById(R.id.edName);
  28.         Password = (EditText) findViewById(R.id.edPassword);
  29.         Info = (TextView) findViewById(R.id.edNumber);
  30.         Login = (Button) findViewById(R.id.edButton);
  31.  
  32.         Info.setText("NO. of attempts remaining: 5");
  33.  
  34.         Login.setOnClickListener(new View.OnClickListener(){
  35.  
  36.             @Override
  37.             public void onClick(View view){
  38.                  validate(Name.getText().toString(), Password.getText().toString());
  39.              }
  40.         });
  41.     }
  42.  
  43.     public void validate(String username, String password){
  44.         if((username=="Aditi") && (password=="12345")) {
  45.             Intent intent = new Intent(MainActivity.this, SecondActivity.class);
  46.             startActivity(intent);
  47.         }else{
  48.             counter--;
  49.  
  50.             Info.setText("NO. of attempts remaining:" + String.valueOf(counter));
  51.  
  52.             if(counter==0){
  53.                 Login.setEnabled(false);
  54.             }
  55.         }
  56.  
  57.     }
  58. }
Add Comment
Please, Sign In to add comment