Change screen (xml) with login button

-1

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.

    
asked by anonymous 16.10.2017 / 19:53

1 answer

1

Probably you should be doing Intent the wrong way, see this simple example:

Intent intent = new Intent(this, SegundaActivity.class);
startActivity(intent);

And you should also remember to register SegundaActivity in AndroidManifest.xml , for example:

<activity
     android:name=".SegundaActivity"
     android:theme="@style/AppTheme">
</activity>

In documentation of Android you can see everything as is done.

    
16.10.2017 / 20:18