Advertisement
Guest User

Untitled

a guest
Dec 14th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. final int counter = 3;
  2.  
  3. //Set the OKButton to accept onClick
  4. OKButton.setOnClickListener(new View.OnClickListener() {
  5. @Override
  6.  
  7. //once onClick is initalized it takes user to page menu
  8. public void onClick(View v) {
  9.  
  10. //display text that was inputed for userText and passText
  11. user = userText.getText().toString();
  12. pass = passText.getText().toString();
  13.  
  14. //create if loop which checks if user and pass equals the credentials
  15. if (user.equals("pshivam") && pass.equals("Bway.857661")) {
  16.  
  17. //display toast access welcome
  18. String welcome = "Access Granted.";
  19.  
  20. //Create a Toast to display the welcome string in the MainActivity.
  21. Toast.makeText(MainActivity.this, welcome, Toast.LENGTH_SHORT).show();
  22. setContentView(R.layout.account_main);
  23. }
  24. //create else if loop which checks if user or pass does not equals the credentials
  25. else if (!user.equals("pshivam") || !pass.equals("Bway.857661")){
  26.  
  27. //displays previous entry
  28. userText.setText(user);
  29. passText.setText(pass);
  30.  
  31. //allows user to re-enter credentials.
  32. user = userText.getText().toString();
  33. pass = passText.getText().toString();
  34.  
  35.  
  36. //display toast access fail
  37. String fail = "Access Denied! Please Try again.";
  38. //Create a Toast to display the fail string in the MainActivity.
  39. Toast.makeText(MainActivity.this, fail, Toast.LENGTH_SHORT).show();
  40. counter--;
  41. if(counter == 0){
  42. finish();
  43. }
  44. }
  45. }
  46. });
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement