Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- final int counter = 3;
- //Set the OKButton to accept onClick
- OKButton.setOnClickListener(new View.OnClickListener() {
- @Override
- //once onClick is initalized it takes user to page menu
- public void onClick(View v) {
- //display text that was inputed for userText and passText
- user = userText.getText().toString();
- pass = passText.getText().toString();
- //create if loop which checks if user and pass equals the credentials
- if (user.equals("pshivam") && pass.equals("Bway.857661")) {
- //display toast access welcome
- String welcome = "Access Granted.";
- //Create a Toast to display the welcome string in the MainActivity.
- Toast.makeText(MainActivity.this, welcome, Toast.LENGTH_SHORT).show();
- setContentView(R.layout.account_main);
- }
- //create else if loop which checks if user or pass does not equals the credentials
- else if (!user.equals("pshivam") || !pass.equals("Bway.857661")){
- //displays previous entry
- userText.setText(user);
- passText.setText(pass);
- //allows user to re-enter credentials.
- user = userText.getText().toString();
- pass = passText.getText().toString();
- //display toast access fail
- String fail = "Access Denied! Please Try again.";
- //Create a Toast to display the fail string in the MainActivity.
- Toast.makeText(MainActivity.this, fail, Toast.LENGTH_SHORT).show();
- counter--;
- if(counter == 0){
- finish();
- }
- }
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement