Android Studio. How to instantiate a method with a view in another class

Asked

Viewed 318 times

0

I have a method in Mainactivity2:

public void addfoto(View view) {

// meu código bla bla bla bla

}

And I want to call this method on Mainactivity. I’m trying this way but it gets the code wrong:

MainActivity2 m2 = new MainActivity2();
m2.addfoto(); 

But it’s not working. How I do ?

  • What is the error that appears? Or no error appears? Do not omit anything, any detail is important to get a proper response

  • You have to matter the class Mainactivity2 if not, it will not work. Any doubt is just read this reply.

  • That’s stupid. It was the import of the class just like the colleague above spoke. Thank you !!!!

  • What if to call Onclicklistner another class? how do I ?

  • This is not a good principle, it is better to put the code of that click in a class that both Activities can call, assuming that it is indeed the same

No answers

Browser other questions tagged

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