Search code examples
androidandroid-fragmentskotlinandroid-tablayoutandroid-livedata

Observe Data at Application level


Hello Team i have below UI enter image description here

When i select different item from drop-down menu in Fragment Report, I need to refresh all data in Fragment chart (including tab1,tab2....tab6) and also in Fragment ReportDetails (tabA,tabB,tabC)

UI Explanation

Parent Fragment -> FragmentReport

Child Fragment -> FragmentReportDetail

FragmentReportDetail has tab layout having 3 tabs(means 3 Tab Fragments..Tab A, Tab B, Tab C) Each Tab A, Tab B and Tab C has tab layout having 6 tabs (means 6 Tab Fragments... Tab 1, Tab 2, ....Tab 6)

So when item changed in parent fragment drop down menu...i need to update (using API network call) data in All Tab fragments. Also i need to pass selected drop down item in all tab fragments to make API call.

How to observe this drop down item selection in all tab fragments.

Thanks in advance.


Solution

  • Here is a how you might achieve the functionality using a shared ViewModel:

    enter image description here