-1

I did a bottomnavigationview with two tabs, then I injected fragments at each of the tabs, I would like to know how to communicate the 2 tabs.
for example, creating an EditText with a button at the first tabs and then retrieving the information at the level of this tab and injecting it into a TextView at the level of the second.
I already tried with the bundle but it did not work when I click on the tabs that must retrieve the information the app stops showing "unfortunately appname has stopped".

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Begginers
  • 35
  • 2
  • 5

1 Answers1

0
  1. It is not recommended to use BottomNavigation with just 2 tabs. Use Tabs instead. Read more.

  2. To communicate between fragments in one activity, just use ViewModel and LiveData from Android Architecture Components.

Tips:

  1. Follow the guidance here on how to share ViewModel data between fragments in one activity. Read more
  2. In the first fragment, bind the the EditText to LiveData.
  3. In the second fragment, observe the LiveData and show it to TextView.
Yosi Pramajaya
  • 3,895
  • 2
  • 12
  • 34