-3

I have the first layout with a button and I would like to go to second layout.

This is my code:

butonSubmit.setOnClickListener(new View.OnClickListener(){
        @Override
        public void onClick(View v) {

            Intent i = new Intent(getApplicationContext(),Verificare.class);
            startActivity(i);

        }
    });

I created a second Java class Verificare and a layout verify that I designed something and I tried this in the second Java class:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.verify);
}

I also added this:

<activity android:name=".Verificare" >
</activity>

to the AndroidManifest.

When I press the button the page doesn`t change. What is wrong ? Thanks in advance i am beginner in Android

Ryan M
  • 18,333
  • 31
  • 67
  • 74
SerbanRamon
  • 97
  • 1
  • 1
  • 7
  • Does this answer your question? [Calling startActivity() from outside of an Activity context](https://stackoverflow.com/questions/3918517/calling-startactivity-from-outside-of-an-activity-context) (read: use `getContext()`, not `getApplicationContext()`) – Ryan M Apr 23 '20 at 02:38

2 Answers2

0
buttonSubmit.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {
        Intent i = new Intent(getApplicationContext(), Verificare.class);
        startActivity(i);
    }

});
aboger
  • 2,214
  • 6
  • 33
  • 47
  • 2
    Please don't post only code as an answer, but also provide an explanation what your code does and how it solves the problem of the question. Answers with an explanation are usually of higher quality, and are more likely to attract upvotes. – Mark Rotteveel Apr 21 '20 at 12:59
0

Where do you place the code for the button onClickListener? Try putting it inside of the onCreate method of an activity.

benjaminv2
  • 109
  • 8