I'm developing an application. You have the option to login. I wanted to know how to move to another xml layout when login and password validated.
The login system is almost ready. I put it in the MainActivity
, I made a private void (oncreate)
by setting the button, and after, in a public void
the code "IF" I put to validate the login and password and thus to show that the login was done. I would like to know how to switch to another XML screen with the button from login validation.
I've tried using Intents to call another activity
within the if rule, but I did not succeed.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btLogin = (Button) findViewById(R.id.btLogin);
btLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TextView tLogin = (TextView) findViewById(R.id.tLogin);
TextView tSenha = (TextView) findViewById(R.id.tSenha);
String Login = tLogin.getText().toString();
String Senha = tSenha.getText().toString();
if(Login.equals("hugo")&&Senha.equals("123")) {
alert("Login realizado com sucesso");
}
else{
alert("Login ou senha incorretos");
}
}
});
}
private void alert(String s) {
Toast.makeText(this,s,Toast.LENGTH_LONG).show();
}
}
My intention was to put in the keys of the if rule an attempt to call another layout.