EditText user, pass;
Button login;
int attempt = 3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pass = (findViewById(R.id.password));
user = (findViewById(R.id.username));
login = (findViewById(R.id.login));
login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (user.getText().toString().equals("jarm") && pass.getText().toString().equals("121916")){
openHome();
}
else {
Toast.makeText(MainActivity.this, "Invalid Account! " + attempt + " attempt left.", Toast.LENGTH_SHORT).show();
attempt--;
if (attempt==0){
login.setEnabled(false);
Toast.makeText(MainActivity.this, "No more Attempt left. Please try again later.", Toast.LENGTH_SHORT).show();
}
}
}
});
}
public void openHome(){
Intent wtc = new Intent(this, Home.class);
startActivity(wtc);
}
}
ANDROID STUDIO APP-DEV | LOGIN USERNAME & PASSWORD
Reviewed by Gin Florita
on
January 19, 2020
Rating:
No comments: