Answer the question
In order to leave comments, you need to log in
How to pass data from fragment to tab?
In fragment "A" I have a CoordinatorLayout, each tab of the coordinator is a separate fragment "B", how can I transfer data from fragment A to fragment B?
I haven't been able to solve this problem for half a day now.
Answer the question
In order to leave comments, you need to log in
The coordinator doesn't have any tabs. However, there are different ways.
The main way to pass data is a bundle of arguments (get/setArguments).
Also, you need to understand that this fragment B of yours is a child fragment (getChildFragmentManager in fragment A?). If yes, then they can communicate directly, via getParentFragment in Fragment B, findFragmentByTag in Fragment A.
If not, then you can use the fragment target mechanism (get/setTargetFragment). Or through activation.
Of course, it is better to cast not to a specific fragment class, but to an interface that will display exactly the actions that are needed.
I have a couple of lectures on this topic, quite old, but fundamentally little has changed.
https://youtu.be/3VXPsCUYioM
https://youtu.be/gD4E_TLbKeU
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question