How to switch from the second to the third screen?

0

Recently I started to develop a small application that relies totally on switching screens from buttons. There are still many details to be resolved, but what worries me now is how to make the switch to change the screen. I have already been able to make the change from the 1st screen to the 2nd, but being on this second screen, I do not know how to go to a third one.

This is the code I'm using to go from the start screen to the next.

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
import android.content.Intent;
import android.view.View.OnClickListener;


public class Entrar extends AppCompatActivity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_entrar);


    Button button2 = (Button) findViewById(R.id.button2);

    button2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setContentView(R.layout.activity_login);
        }

    });

}}

Now, I would like that by clicking a button (called "buttonEntrar") on the screen that is called by that command, I would be directed to a third layout (called "cnaps.xml"), had done, but did not work, how to proceed?

Second screen code:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<Button
    android:fontFamily="@font/tw_cen"
    android:id="@+id/button5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentStart="true"
    android:layout_marginBottom="21dp"
    android:layout_marginStart="17dp"
    android:text="VOLTAR"
    android:textSize="25sp"
    android:onClick="GotoMain"/>

<Button
    android:id="@+id/buttonEntrar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentEnd="true"
    android:layout_alignTop="@+id/button5"
    android:layout_marginEnd="16dp"
    android:fontFamily="@font/tw_cen"
    android:onClick="sendMessage"
    android:text="ENTRAR"
    android:textSize="25sp" />

<TextView
    android:id="@+id/textView5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/editText"
    android:layout_alignStart="@+id/button5"
    android:fontFamily="@font/tw_cen"
    android:text="Insira E-mail:"
    android:textSize="25sp" />

<TextView
    android:id="@+id/textView6"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/editText2"
    android:layout_alignStart="@+id/button5"
    android:fontFamily="@font/tw_cen"
    android:text="Insira Senha:"
    android:textSize="25sp" />

<EditText
    android:id="@+id/editText"
    android:layout_width="225dp"
    android:layout_height="wrap_content"
    android:layout_alignEnd="@+id/button6"
    android:layout_alignParentTop="true"
    android:layout_marginTop="170dp"
    android:ems="10"
    android:inputType="textPersonName" />

<EditText
    android:id="@+id/editText2"
    android:layout_width="226dp"
    android:layout_height="wrap_content"
    android:layout_alignEnd="@+id/button6"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="205dp"
    android:ems="10"
    android:inputType="textPassword" />

<CheckBox
    android:id="@+id/checkBox"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignEnd="@+id/button6"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="143dp"
    android:fontFamily="@font/tw_cen"
    android:textSize="15sp"
    android:text="Esqueci minha senha!" />


<TextView
    android:id="@+id/textView7"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentEnd="true"
    android:layout_alignParentTop="true"
    android:layout_marginEnd="81dp"
    android:layout_marginTop="46dp"
    android:fontFamily="@font/campus_relief"
    android:text="CNAPS"
    android:textSize="30sp" />

    
asked by anonymous 25.05.2018 / 15:14

1 answer

0

What you want is this, within the onClick() method of the button you are going to create:

Intent i = new Intent(ActivityOndeVoceEsta.this, ActivityParaOndeVoceQuerIr.class);
startActivity(i);

Do this even for this login activity that you have already implemented.

Do not forget to add the new activities in manifest.xml

Learn more about starting a new activity here .     

25.05.2018 / 19:47