Answer the question
In order to leave comments, you need to log in
How to access fragments in MainActivity?
The application has three tabs. They are created from MainActivity using ViewPager and ViewPageAdapter. Each tab has a recyclerview. When clicking on the tab title, the specific recyclerview scrolls to the top. To do this, I want to put a listener for the menu in MainActivity.
How to access fragment elements from the main activity through findViewById?
Answer the question
In order to leave comments, you need to log in
In general, of course, you can do this, but it is not necessary. A fragment must completely encapsulate the behavior of everything it has inside. The activity doesn't need to know what's inside the fragment. A fragment should not know anything about other fragments.
The standard decision such - becomes the interface with the necessary methods. The fragment implements this interface. Activity pulls methods. Activity can also implement similar interfaces and the fragment can then pull these methods.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question