My bottom navigation view not working. When i click on items my fragment in not loading.
beginTransaction()
may produce NullPointerException.
This is my Activity :
public static void enableNavigation(Context context, final BottomNavigationViewEx view, final FragmentManager supportFragmentManager){
view.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
Fragment fragment;
switch (item.getItemId()){
case R.id.nav_home:
fragment = new FragmentMarker();
loadFragment(fragment);
return true;
case R.id.nav_bookmark:
fragment = new FragmentBookmark();
loadFragment(fragment);
return true;
case R.id.nav_blog:
fragment = new FragmentBlog();
loadFragment(fragment);
return true;
case R.id.nav_notification:
fragment = new FragmentNotification();
loadFragment(fragment);
return true;
case R.id.nav_account:
fragment = new FragmentAccount();
loadFragment(fragment);
return true;
}
return false;
}
private void loadFragment(Fragment fragment) {
// load fragment
FragmentTransaction transaction = fragment.getFragmentManager().beginTransaction();
transaction.replace(R.id.container, fragment);
transaction.addToBackStack(null);
transaction.commit();
}
});
And this is one of my fragments :
private void setupBottomNavigationView(){
Log.d(TAG, "setupBottomNavigationView: Setting up BottomNavigationView");
BottomNavigationViewEx bottomNavigationViewEx = getView().findViewById(R.id.bottom_navigation);
BottomNavigationViewHelper.setupBottomNavigationView(bottomNavigationViewEx);
BottomNavigationViewHelper.enableNavigation(getContext(), bottomNavigationViewEx, getFragmentManager());
Menu menu = bottomNavigationViewEx.getMenu();
MenuItem menuItem = menu.getItem(ACTIVITY_NUM);
menuItem.setChecked(true);
}