Hello. I'm just a beginner and ask not to judge strictly and help. The problem is that I have 5 buttons on the BottomNavigationBar and the question is how to implement the switch, that is, so that by pressing the button other information is displayed, do I need to create other activities? Further I provide the code.

package --------; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.design.widget.BottomNavigationView; import android.support.v7.app.AppCompatActivity; import android.view.MenuItem; public class Navigation extends AppCompatActivity { private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener = new BottomNavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { switch (item.getItemId()) { case R.id.navigation_home: return true; case R.id.navigation_lists: return true; case R.id.navigation_sale: return true; case R.id.navigation_maps: return true; case R.id.navigation_regulation: return true; } return false; } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_navigation); BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation); navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener); } } 

It may be very simple, but I need help. Thank you in advance.

  • BottomNavigationBar typically used to switch fragments. - post_zeew

1 answer 1

There should be one activity in which BottomNavigationView is located BottomNavigationView . When you click on the tab, the Fragment should be replaced in the part of the activation in which the content being changed is located.

 <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent"> <FrameLayout android:id="@+id/content" android:layout_width="match_parent" android:layout_height="match_parent"/> <android.support.design.widget.BottomNavigationView android:id="@+id/bottom_navigation" android:layout_width="match_parent" android:layout_height="wrap_content"/> </android.support.design.widget.CoordinatorLayout> 

Here content is the layout into which the fragment is placed (and is accordingly replaced with the new one).

There are alternatives to fragments in the form of View-based concepts, such as Conductor , but for beginners, it is useful to first work with fragments.