0
        navigationView = (BottomNavigationView) findViewById(R.id.navigation);
    navigationView.setOnItemSelectedListener(new NavigationBarView.OnItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            navigationView.postDelayed(() -> {
                int itemId = item.getItemId();
                System.out.println("it works");
                if (itemId == R.id.homeFragment) {
                    startActivity(new Intent(getApplicationContext(), HomeActivity.class));
                } else if (itemId == R.id.searchFragment) {
                    startActivity(new Intent(getApplicationContext(), SearchActivity.class));
                } else if (itemId == R.id.artistFragment) {
                    startActivity(new Intent(getApplicationContext(), ArtistProfileActivity.class));
                } else if (itemId == R.id.libraryFragment) {
                    startActivity(new Intent(getApplicationContext(), FavoriteActivity.class));
                }
                finish();
            }, 50);
            return true;
        }
    });

The navigation bar is clickable but it does not bring me to the next page There is no error messages. It just stays on the main page. I am not really sure how the BottomNavigationView works and most of this code is from online and I have problems understanding it.

Alpha1229
  • 11
  • 1
  • 8

1 Answers1

0

In your question you said you didn't really know how the BotttomNavigationView works and I have provided a link here to one of the best android development tutors on YouTube that will help you understand it in-depth but for further clarity on how to do it as from the code you just provided at the top then I would suggest that you use a switch case as I used below and worked well for me as per the CodingInFlow Tutorial

private final BottomNavigationView.OnNavigationItemSelectedListener navListener =
        item -> {
            Fragment selectedFragment = null;

            switch (item.getItemId()) {
                case R.id.home:
                    selectedFragment = new HomeFragment();
                    break;

                case R.id.categories:
                    selectedFragment = new CategoriesFrag();
                    break;

                case R.id.cart:
                    selectedFragment = new CartFragment();
                    break;

                case R.id.transactions:
                    selectedFragment=new TransactionsFrag();
                    break;

                case R.id.customerProfile:
                    selectedFragment=new ProfileFragment();
                    break;

            }

            assert selectedFragment != null;
            getSupportFragmentManager().beginTransaction().replace(R.id.customer_container, selectedFragment).commit();
            return true;
        };
Mosericko
  • 116
  • 6
  • is there a way to do it with activities instead of fragments or to just go to the activities – Alpha1229 Aug 06 '21 at 03:49
  • using with activities is not really recommended as explained [here](https://stackoverflow.com/a/49421748/13259575) but following the link you'll learn to do it using activities though it is highly recommended to use fragments – Mosericko Aug 06 '21 at 04:01