How to change from second to third screen?

Asked

Viewed 625 times

0

A little while ago I started to develop a small application that is totally based on changing screens from buttons. There are still many details to be solved, but what worries me now is how to make the command to change screen. I already managed to change the 1°screen to 2°, but being in this second screen, I don’t know how to go to a third screen.

This is the code I’m using to go from the home 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 to click on a button (called "buttonEntrar") present on the screen that is called by this command, be directed to a third layout (called "cnaps.xml"), I have tried to do in a similar way to what I had done, but it did not work, how to proceed?

Code from the second screen:

<?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" />

  • Add the code of the second screen, on which you want to call the third screen.

1 answer

0


What you want is this here, within the method onClick() button you will create:

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

Do it, even for this one Activity login you have already implemented.

Don’t forget to add the new ones activities in the manifest.xml

Learn more about starting a new one Activity here.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.