-1
I am developing an application. It has 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 in the tab of MainActivity
, made a private void (oncreate)
setting the button, and after, in a public void
the code "IF" I put to validate the login and password and so show that the login was performed. I wanted to know how to switch to another XML screen with the button from login validation.
I’ve tried to use Intents to call another activity
within the if rule, but was unsuccessful.
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 rule if an Intent to call another layout.
Hugo, also post the code you are writing, it is easier to help you
– Leonardo Dias
Okay, I put in the code and what I’m trying to.
– Hugo Gaia