I need from one fragment to get access to the methods of another fragment.

How to do it?

  • Can be made static or variables with fragments, or methods - Real KEK

2 answers 2

The abstract class FragmentManager manages fragments, it is logical that you can get a Fragment object. Everything is as usual - we cast findFragmentById() on the FragmentManager determine which fragment you need R.id.myFrag , R.id.myFrag fragment to the necessary type to get access (to determine the correct link of the object) to your public methods of the object. And then, as usual, myFrag.callMyMethod ().

  • Is it possible in more detail? Otherwise, I do not have a findFragmentById method. - Fedia

Since the management is carried out by fragments from the Activity, it would be correct to define methods in the Activity, so that later they can be called from any other fragment. But you can make static methods, but this is a rake. This is how we call the activation method from the fragment:

 Someactivity aa = (Someactivity)getContex(); aa.nameofmethod(); 
  • I know from activations how to call. I am now transferring everything from the activation to the fragment, because I said that this approach is more correct. - Fedia