2021年1月5日星期二

How to use a button to open a new page in android studio

I'm trying to use a button to change from Main Activity on android studio to Main Activity 2 and I get the error

no suitable constructor found for Intent(<anonymous OnClickListener>,Class<MainActivity2>)                  Intent intent = new Intent(this, MainActivity2.class);                                  ^  

I'm on version 4.1 and I want to assume i'm following an old tutorial or I just missed some punctuation. This is my code:

        buttonPage.setOnClickListener(new View.OnClickListener() {              @Override              public void onClick(View v) {                  openMainActivity2();              }                public void openMainActivity2(){                  Intent intent = new Intent(this, MainActivity2.class);                  startActivity(intent);  
https://stackoverflow.com/questions/65589579/how-to-use-a-button-to-open-a-new-page-in-android-studio January 06, 2021 at 10:54AM

没有评论:

发表评论