android studio activity does not open with click button

0

My problem is this. my application has a welcome screen where the user ckick the "continue" button and goes to the next screen. The next one contains a menu with several buttons. my problem is that I can not open another activity on the second screen (on the first screen that opens normal) more or less this scheme below (| activity1> button continues | > >> activity2> continue2 | > does not respond | screen3 > > does not open) to praise and test the apk in a galaxy grand duos 4.2.2

code below  code 1 screen (welcome).

public class Main2Activity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
Button button7 = (Button) findViewById(R.id.button7);

button7.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        setContentView(R.layout.activity_main4);
    }
});}}

Screen 2 code

public class Main4Activity extends AppCompatActivity {
private  Button prova;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main4);

prova = (Button) findViewById(R.id.button5);

    prova.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        Intent intent = new Intent( Main4Activity.this, 
    Main3Activity.class);
        startActivity(intent);
    }
});

}}

screen 2 xml butao code

            <Button
            android:id="@+id/button5"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/button4"
            android:layout_marginTop="11dp"
            android:text="tela 2"/>

    
asked by anonymous 10.12.2017 / 02:45

1 answer

0

Hello,

Your App problem is in the onClick method of the first Activity , when you run the setContentView(R.layout.activity_main4); method you are only loading the screen layout, not passing the processing control to the next activity , then the onClick of prova.setOnClickListener method is not executed. To correct the error, create a Intent to call the Main4Activity . Replace the excerpt:

setContentView(R.layout.activity_main4);

by:

Intent intentProva = new Intent( Main2Activity.this, 
Main4Activity.class);
    startActivity(intentProva);
    
10.12.2017 / 14:27