title: Android Studio Bottom Bar Nav: How do I add to each fragment?
body: <p>I followed a tutorial online to create a Bottom Bar <code>Navigation</code>, but the guy didn't explain clearly how to add stuff to each fragment and swap between the fragments. I want to add an <code>EditText</code> to the home page as an example on how to add items to the fragments. Here's my code:</p>
  
  <p><strong>Main Activity -</strong></p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
  private static final String TAG_FRAGMENT_CATA = "tag_frag_cata";
  private static final String TAG_FRAGMENT_HOME = "tag_frag_home";
  private static final String TAG_FRAGMENT_SETTINGS = "tag_frag_settings";
  
  private BottomNavigationView bottomNavigationView;
  
  private List&lt;BottomBarFragment&gt; fragments = new ArrayList&lt;&gt;(3);
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_nav);
  
          bottomNavigationView.setOnNavigationItemSelectedListener(
                  new BottomNavigationView.OnNavigationItemSelectedListener() {
                      @Override
                      public boolean onNavigationItemSelected(@NonNull MenuItem item) {
  
                          switch (item.getItemId()) {
                              case R.id.bottombaritem_cata:
                                  switchFragment(0, TAG_FRAGMENT_CATA);
                                  return true;
                              case R.id.bottombaritem_home:
                                  switchFragment(1, TAG_FRAGMENT_HOME);
                                  return true;
                              case R.id.bottombaritem_settings:
                                  switchFragment(2, TAG_FRAGMENT_SETTINGS);
                                  return true;
                          }
                          return false;
                      }
                  });
  
          buildFragmentsList();
  
          switchFragment(1, TAG_FRAGMENT_HOME);
  
      }
  
      private void buildFragmentsList() {
          BottomBarFragment cataFragment = buildFragment("Categories");
          BottomBarFragment homeFragment = buildFragment("Home");
          BottomBarFragment settingsFragment = buildFragment("Settings");
  
          fragments.add(cataFragment);
          fragments.add(homeFragment);
          fragments.add(settingsFragment);
      }
  
      private BottomBarFragment buildFragment(String title) {
          BottomBarFragment fragment = new BottomBarFragment();
          Bundle bundle = new Bundle();
          bundle.putString(BottomBarFragment.ARG_TITLE, title);
          fragment.setArguments(bundle);
          return fragment;
      }
  
      private void switchFragment(int pos, String tag) {
          getSupportFragmentManager().beginTransaction().replace(R.id.frame_fragmentholder, fragments.get(pos), tag).commit();
      }
  }
  </code></pre>
  
  <p><strong>Bottom Bar Activity -</strong></p>
  
  <pre><code>public class BottomBarFragment extends Fragment {
      public static final String ARG_TITLE = "arg_title";
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  
          View rootView = inflater.inflate(R.layout.bottom_bar_fragment, container, false);
  
          return rootView;
      }
  
  }
  </code></pre>
  
  <p><strong>XML for the Main Activity</strong></p>
  
  <pre><code>&lt;android.support.constraint.ConstraintLayout 
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context=".MainActivity"&gt;
  
  &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.design.widget.BottomNavigationView
      android:id="@+id/bottom_nav"
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:background="?android:attr/windowBackground"
      app:itemBackground="@android:color/white"
      app:itemIconTint="@android:color/black"
      app:itemTextColor="@android:color/black"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintLeft_toLeftOf="parent"
      app:layout_constraintRight_toRightOf="parent"
      app:menu="@menu/bottombar_menu" /&gt;
  
  &lt;FrameLayout
      android:layout_width="0dp"
      android:layout_height="0dp"
      app:layout_constraintBottom_toBottomOf="@+id/bottom_nav"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintTop_toTopOf="parent"&gt;
  
      &lt;FrameLayout
          android:id="@+id/frame_fragmentholder"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_marginBottom="?attr/actionBarSize"&gt;
  
      &lt;/FrameLayout&gt;
  
      &lt;android.support.design.widget.BottomNavigationView
          android:layout_width="match_parent"
          android:layout_height="match_parent" /&gt;
  
  &lt;/FrameLayout&gt;
  
  &lt;/android.support.constraint.ConstraintLayout&gt;
  </code></pre>
  
  <p>XML Layout file -</p>
  
  <pre><code>&lt;android.support.constraint.ConstraintLayout 
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context=".BottomBarFragment"&gt;
  
  &lt;/android.support.constraint.ConstraintLayout&gt;
  </code></pre>
  
  <p>If someone could explain how to use this code, I would really appreciate it!</p>