There is a method in MainActivity.cs ... let's call it Test (). And there is a fragment. which describes a certain button

button = view.FindViewById<Button>(Resource.Id.button1); private void button_Click(object sender, EventArgs e) { //вызов метода Test() } 

How to implement a call to this method?

PS xamarin android

    3 answers 3

    No one helped me, and I had to understand myself. To call the Activation method from a fragment, you need to do so in the fragment code: MainActivty ma = (MainActivity)this.Activity; and then access any method through ma.test(); Otherwise there were problems with either data transfer or method type ...

      So it will be more correct:

      if (getActivity ()! = null) {MainActivity ma = (MainActivity) getActivity (); ma.test (); }

        Try this.MainActivity.Test() .

        • In this version, he says that this method simply does not exist. Although he is. - Phobos92