0

I recently implemented the onBackPressed method on my fragments, this works well but there is a little bug with my nav bar...

Pictures are better than a long speech !

In this picture : The app is launched

the app is launched

In this picture : I clicked to the last button on the right (Infos)

I was on the first button on the left (The map) then i clicked the last button on the right (Infos)

In this picture : I want to go back on the first fonctionnality (The map) so i clicked on the return key

I want to go back on the first fonctionnality (The map) so i clicked on the return key

As you can see, in the last screen the good fragment is displayed but the button "Infos" of the nav bar is still clicked !

This is my code to launch the fragments :

private BottomNavigationView.OnNavigationItemSelectedListener navListener =
        new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                Fragment selectedFragment = null;

                switch (item.getItemId()) {
                    case R.id.nav_profile:
                        AccessToken accessToken = AccessToken.getCurrentAccessToken();
                        if(token ==null) {
                            selectedFragment = new EnregistrementFragment();
                            //selectedFragment = new ProfileFragment();
                        }else{
                            selectedFragment = new ProfileFragment();
                        }
                        break;
                    case R.id.nav_map:
                        selectedFragment = new LocalisationFragment();
                        break;
                    case R.id.nav_group:
                        selectedFragment = new ScoreFragment();
                        break;
                    case R.id.nav_faq:
                        selectedFragment = new InfosFragment();
                        break;
                    case R.id.nav_favorite:
                        selectedFragment = new FavoriteFragment();
                        break;
                }
                FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
                transaction.replace(R.id.fragment_container, selectedFragment);
                transaction.addToBackStack("FirstFragment");
                transaction.commit();

                return true;
            }
        };

And my method onBackPressed() :

    public void onBackPressed() {
    int count = getFragmentManager().getBackStackEntryCount();

    if (count == 0) {
        super.onBackPressed();
        //additional code
    } else {
        getFragmentManager().popBackStack();
    }
}

My question is : Have you an idea to refresh the navbar ?

Thank you in advance and really sorry for the bad english !

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Gwynbleidd
  • 43
  • 7

0 Answers0