F
F
foonfyrick2021-03-16 16:09:36
Android
foonfyrick, 2021-03-16 16:09:36

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

2 answer(s)
D
Denis Zagaevsky, 2021-03-17
@foonfyrick

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

J
Jacen11, 2021-03-16
@Jacen11

Intent (main)
Static field for activity (cannot be)
SharedPreferences
Bus
Database
Using internal storage
Using external storage
ViewModel

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question