title: addTab() not adding any TabLayout.Tab on callback
body: <p>When adding tabs on the OnCreate theres no problem, tabs are added normally, yet when adding tabs on the onChange callBack of the LiveDataObserver..nothing happens.</p>
  
  <p>I have a ViewPager with 2 Fragments, inside the 2nd Fragment I have a second Viewpgaer with another 2 Fragemnts, this second vp has a com.google.android.material.tabs.TabLayout but the TabLayout is NOT coupled via .setupWithViewPager().</p>
  
  <p><strong>EDIT</strong>: The Configuration would be something like this:</p>
  
  <p>MainActivity (Nav) -> MainFrag (ViewPager) -> ChildFrag (at 1st pos)...&lt;- Here is the TabLayout</p>
  
  <p><strong>Continue</strong>:</p>
  
  <p>This TabLayout is showing only the contents of the second most inner viewPager, that means that it should only display 2 tabs, nothing more.</p>
  
  <p>But I want to add those two tabs via LiveData callbacks.</p>
  
  <p>I particularly dont want them (the viewpager and the tablayout )coupled because I want the Fragments to be created once, but I also want the tabs to appear as if the user is creating them on the fly.</p>
  
  <p>If I create the Fragemtns, with the sole purpose of adding tabs, I run the risk of fetching info from the DB everytime this is done, even if the user picks the same option twice.</p>
  
  <p>Also, if the fragments are already constructed the paging becomes smooth.
  At all cost I avoid using the notifyDataSetChanged() because I dont like how teh data travels with that option, this is the main reason.</p>
  
  <p>So I want to .addTab() in the onChange of the LiveData, so that I can create Tabs with the titles that the LiveData provides.</p>
  
  <p>Yet nothing happens</p>
  
  <pre><code>    &lt;com.google.android.material.tabs.TabLayout
          android:id="@+id/tablayout"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:background="@color/colorPrimary"
          app:tabSelectedTextColor="@android:color/white"
  
  
          app:layout_constraintBottom_toTopOf="@id/guideline"
          app:layout_constraintTop_toTopOf="parent"
          app:tabTextColor="@android:color/black"
          &gt;
  </code></pre>
  
  <p>That is the XML</p>
  
  <pre><code>public class FlyHighSubFragment extends Fragment {
  
  
  
  
      private WeakReference&lt;FlyHighActivity&gt; mContextWeakReference;
      private MySubFragmentPagerAdapter mAdapter;
      private FragmentFlyhighSubBinding binding;
  
  
      private TabLayout mTabLayout;
  
      private SharedViewModel mSharedViewModel;
  
  
  
      @Override
      public void onAttach(@NonNull Context context) {
          super.onAttach(context);
          if (context instanceof FlyHighActivity) {
  
              mContextWeakReference = new WeakReference&lt;&gt;((FlyHighActivity)context);
  
          }
      }
  
      @Nullable
      @Override
      public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
  
  
  
          binding = DataBindingUtil.inflate(inflater,
                  R.layout.fragment_flyhigh_sub, container, false);
  
  
          mAdapter = new MySubFragmentPagerAdapter(getChildFragmentManager());
  
          binding.mainContainer.setAdapter(mAdapter);
  
  
  
          mTabLayout = binding.tablayout;
  
          mTabLayout.addOnTabSelectedListener(new TabLayout.BaseOnTabSelectedListener() {
              @Override
              public void onTabSelected(TabLayout.Tab tab) {
                  binding.mainContainer.setCurrentItem(tab.getPosition());
              }
  
              @Override
              public void onTabUnselected(TabLayout.Tab tab) {
  
              }
  
              @Override
              public void onTabReselected(TabLayout.Tab tab) {
  
              }
          });
  
          binding.mainContainer.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(mTabLayout));
  }
  
      @Override
      public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
          super.onViewCreated(view, savedInstanceState);
          mSharedViewModel = ViewModelProviders.of(mContextWeakReference.get()).get(SharedViewModel.class);
  /*called on the process of going from page [0][0] to page [1][0]*/
          mSharedViewModel.getUserName().observe(getViewLifecycleOwner(), new Observer&lt;String&gt;() {
              @Override
              public void onChanged(String s) {
  
                  mTabLayout.addTab(mTabLayout.newTab().setText(s));
  
  
  
  
              }
          });
  /*called on the process of going from [1][0] to [1][1]*/
          mSharedViewModel.getSessionTitle().observe(getViewLifecycleOwner(), new Observer&lt;String&gt;() {
              @Override
              public void onChanged(String s) {
              mTabLayout.addTab(mTabLayout.newTab().setText(s));
              }
          });
  
      }
  
  }
  </code></pre>
  
  <p><strong>EDIT:</strong></p>
  
  <p>My SharedViewModel:</p>
  
  <pre><code>public class SharedViewModel extends ViewModel {
  
      private static final String TAG = "SharedViewModel";
  
  /*Each one of this Strings are passed from Fragment to Fragment, some of them trigger a Firebase listener, others provide view data for the Fragment.*/
  
  /*All of them do their job properly, even the ones called inside the FlyHighSubFragment which is the Fragment that shelters the TabLayout*/
  
      private MutableLiveData&lt;String&gt; uId = new MutableLiveData&lt;&gt;();
      private MutableLiveData&lt;String&gt; userName = new MutableLiveData&lt;&gt;();
      private MutableLiveData&lt;String&gt; chatRef = new MutableLiveData&lt;&gt;();
      private MutableLiveData&lt;String&gt; sessionTitle = new MutableLiveData&lt;&gt;();
      private MutableLiveData&lt;Sessions&gt; session = new MutableLiveData&lt;&gt;();
  
      public SharedViewModel() {
  
      }
  
      public MutableLiveData&lt;Sessions&gt; getSession() {
          return session;
      }
  
      public void setSession(Sessions session) {
          this.session.setValue(session);
      }
  
      public MutableLiveData&lt;String&gt; getSessionTitle() {
          return sessionTitle;
      }
  
      public void setSessionTitle(String sessionTitle) {
          this.sessionTitle.setValue(sessionTitle);
      }
  
      public MutableLiveData&lt;String&gt; getUserName() {
          return userName;
      }
  
      public void setUserName(String userName) {
          this.userName.setValue(userName);
      }
  
      public LiveData&lt;String&gt; getUid() {
          return uId;
      }
  
      public void setUid(String input) {
          uId.setValue(input);
      }
  
      public MutableLiveData&lt;String&gt; getChatRef() {
          return chatRef;
      }
  
      public void setChatRef(String chatRef) {
          this.chatRef.setValue(chatRef);
      }
  
  }
  </code></pre>
  
  <p>This is my SubFragmentPagerAdapter, which is the Adapter for the inner most ViewPager (the one that uses the getChildFragmentManager())</p>
  
  <p>One important thing to mention is that this is the viewPager BELOW the TabLayout, BUT The TabLayout's Fragment has a parent which is another ViewPager and has an identical configuration....FragmentPagerAdapter, "BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT", and Fragments initialized in the constructor, you can see there is no notifyDatasetChanged() because I manage all info through LiveData callbacks:</p>
  
  <pre><code>public class MySubFragmentPagerAdapter extends FragmentPagerAdapter {
  
      private ChatFragment mChatFragment;
      private SessionsFragment mSessionsFragment;
  
      public MySubFragmentPagerAdapter(@NonNull FragmentManager fm,
                                       FlyHighUser flyHighUser,
                                       MyPagerController.FragmentPager fragmentPagerController) {
          super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
  
          mChatFragment = ChatFragment.newInstance(flyHighUser);
          mSessionsFragment = new SessionsFragment();
  
  /*This is a listener I made that allows the Fragments to be able to change the pages of their parent viewPgaer.*/
          mSessionsFragment.setSessionFragmentInterface(fragmentPagerController);
  
  
      }
  
  
      private static final int NUMBER_OF_FRAGMENTS = 2;
  
      @NonNull
      @Override
      public Fragment getItem(int position) {
          switch (position) {
              case 0:
                  return mSessionsFragment;
              case 1:
                  return  mChatFragment;
          }
          return null;
      }
  
  
      @Override
      public int getCount() {
          return NUMBER_OF_FRAGMENTS;
      }
  
  
  
  
  }
  </code></pre>
  
  <p>The complete process should look like this:</p>
  
  <p>MainActivity(Nav) / MainFrag(viewPager) / Frag(at 0)</p>
  
  <pre><code>@Override
  public void onItemClick(String uID, String userName) {
  
  
  /*Set the values that Fragment at position 1 should solve, this include connecting the FireBase Listener with the uid, and getting the userName String*/
          mSharedViewModel.setUid(uID);
          mSharedViewModel.setUserName(userName);
  
  /* this changes the page to position 1*/
  
      fragmentPagerController.scrollToFragment(1);
  }
  </code></pre>
  
  <p>When the page changes to 1, two things must happen simultaneously, A tab must be added, and the SessionsFragment (created at initialization), must add a Firebase Listener to the given reference</p>
  
  <p>MainActivity(Nav) / MainFrag(viewPager) / Frag(at 1)(subViewPgaer + TabLayout).</p>
  
  <pre><code>    @Override
      public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
          super.onViewCreated(view, savedInstanceState);
          mSharedViewModel = ViewModelProviders.of(mContextWeakReference.get()).get(SharedViewModel.class);
          mSharedViewModel.getUserName().observe(getViewLifecycleOwner(), new Observer&lt;String&gt;() {
              @Override
              public void onChanged(String s) {
  /*The Tab is added but not drawn*/
                  mTabLayout.addTab(mTabLayout.newTab().setText(s));
  
  
  
  
              }
          });
          mSharedViewModel.getSessionTitle().observe(getViewLifecycleOwner(), new Observer&lt;String&gt;() {
              @Override
              public void onChanged(String s) {
  /* The Tab is added but not drawn*/
              mTabLayout.addTab(mTabLayout.newTab().setText(s));
              }
          });
  }
  </code></pre>
  
  <p>MainActivity(Nav) / MainFrag(viewPager) / Frag(at 1)(subViewPgaer + TabLayout) / Frag(at 0) &lt;- AKA: SessionsFragment</p>
  
  <pre><code>            @Override
              public void onActivityCreated(@Nullable Bundle savedInstanceState) {
                  super.onActivityCreated(savedInstanceState);
                  mSharedViewModel = ViewModelProviders.of(getActivity()).get(SharedViewModel.class);
                  mSharedViewModel.getUid().observe(getViewLifecycleOwner(), new Observer&lt;String&gt;() {
                      @Override
                      public void onChanged(String s) {
  
                          uid = s;
          /*this works perfectly fine, I wanted the Firebase data to be bound by the MainActivity LifeCycle.
  Observer is added only once, and there is only one Firebase Listener at any given moment (italian chef kiss) BTW observeUserSessions() is a LiveData setter for the observer, lifeCycleOwner and Firebase reference*/
                          mContextWeakReference.get().observeUserSessions(mObserver, "sessions/" + s);
  
  
                      }
                  });
                  mSharedViewModel.getUserName().observe(getViewLifecycleOwner(), new Observer&lt;String&gt;() {
                      @Override
                      public void onChanged(String s) {
                          clientName = s;
      /*this is viewDataBinding*/
                          binding.setClientName(clientName);
  
                      }
                  });
              }
  </code></pre>
  
  <p>There are no error messages, the tabs are added but not displaying.</p>