I am creating a Android application and the fist activity that will open will be a password entry. For know the password has already been set in a variable with the value "admit". I have created a if statement to check what value the user has entered and then compare it to the variable, and if the values match then go to the home screen, however it keeps saying it is the wrong password. Can anybody take a look at my code and advise were i am going wrong.
public class Password extends ActionBarActivity implements View.OnClickListener { protected String password = "admin"; String getPassword;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_password);
Button passwordButton = (Button) findViewById(passwordbutton);
EditText passwordInput = (EditText) findViewById(R.id.password);
getPassword = (passwordInput.getText().toString());
passwordButton.setOnClickListener(this);
}
public void onClick(View v) {
if (getPassword.equals(password)) {
Intent goHome;
goHome = new Intent(this, home.class);
startActivity(goHome);
} else {
AlertDialog.Builder wrongPasswordBuilder = new AlertDialog.Builder(this);
wrongPasswordBuilder.setTitle(getString(R.string.wrongPasswordTitle));
wrongPasswordBuilder.setMessage(getString(R.string.wrongPasswordTryAgain));
wrongPasswordBuilder.setPositiveButton("ok", null);
AlertDialog dialog = wrongPasswordBuilder.show();
}
}
Aucun commentaire:
Enregistrer un commentaire